Tuesday, February 8, 2011

increasing java heap size in build file

I recently had to increase the java heap size for running my program. This did not seem obvious in the first few hits from google


<target name="run" depends="compile">
<java fork="true" classname="your.class.name">
<classpath>
<path refid="classpath" />
<path location="${dist}/parallelImpl.jar" />
</classpath>
<jvmarg line="-Xms256m -Xmx3000m" />
</java>
</target>

This specifies a minimum size of 256 MB and a maximum size of 3000MB.

A good article about java memory management

http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf

Tuesday, January 11, 2011

Using Zend Picasa API for getting details for last 10 public images

Here is some php code
This PHP code can be used to get

  • The last 10 public pics for a user
  • The URL's to the original images
  • The URL's to the thumbnails
  • The URL's to the original Picasa page where the images are hosted.


(please pardon the formatting)
<?php

/*
display the last 10 public picasa pics for the user
*/

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Photos');
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Uri_Http');
require_once('Zend/Oauth/Consumer.php');
require_once ('Zend/Gdata/Photos.php');






//set google parameters: last three parameters are constant for google api's

$oauthOptions = array(
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
'version' => '1.0',
'consumerKey' => $CONSUMER_KEY,
'consumerSecret' => $CONSUMER_SECRET,
'signatureMethod' => 'HMAC-SHA1',
'callbackUrl' => 'your call back URL here',
'requestTokenUrl' =>'https://www.google.com/accounts/OAuthGetRequestToken',
'userAuthorizationUrl' => '$https://www.google.com/accounts/OAuthAuthorizeToken',
'accessTokenUrl' => 'https://www.google.com/accounts/OAuthGetAccessToken'
);


//select the token for this user from the DB
//this is the OAUTH access token for this user for Picasa. Look at other blog(OAUTH-coming soon)         //for more details
$accessToken=unserialize($result->token);


//get google client and last 10 public photos
$httpclient=$accessToken->getHttpClient($oauthOptions);
$gp=new Zend_Gdata_Photos($httpclient,"fun-widgets");

        // Creates a Zend_Gdata_Photos_UserQuery
$query = $gp->newUserQuery();
// indicate the user's feed to retrieve. default uses the user whose token we are using
$query->setUser("default");


// set to only return photos
// the default kind value for a user feed is to include only albums
$query->setKind("photo");
$query->setAccess("public");
$query->setMaxResults("10");

try {
        $userFeed= $gp->getUserFeed(null, $query);

                        //the user name in case you need it
                        //$username=$userFeed->getGphotoUser()->getText();
//var_dump($username);




//iterate over the original image URL's and get the the main picasa URL
foreach ($userFeed as $entry) {
$tmpArray=$entry->getLink();

                                //here is your public picasa URL for the image
                                 var_dump($tmpArray[1]->getHref());
                              
                                //in case you can manage with the thumbnail
$thumbnail = $entry->getMediaGroup()->getThumbnail();
$imageUrl=$thumbnail[1]->url;

                                //url for the original image
                                $content= $entry->getMediaGroup()->getContent();
$imageUrl= $content[0]->getUrl();


}


} catch (Zend_Gdata_App_HttpException $e) {
echo "Error: " . $e->getMessage() . "<br >\n";
if ($e->getResponse() != null) {
echo "Body: <br />\n" . $e->getResponse()->getBody() .
"<br />\n";
}

} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getMessage() . "<br />\n";
}






?>