Search code examples
iosobjective-cpicasa

Upload image to Picasa with Objective-C on iPhone


I was wondering if anyone had any information of code that they have used to upload an image to Picasa. I really only need the code to upload images, I have everything working to get the image feed and view it, but going the other way is giving me a problem.

Google does not really provide any good documentation for how to do this. Any help would be greatly appreciated.


Solution

  • Check this code:

    GDataServiceGooglePicasaWeb* service =
     [[GDataServiceGooglePicasaWeb alloc] init];
    
    [service setUserCredentialsWithUsername:@"[email protected]"
     password:@"mypasswd"];
    
    // get the URL for the album
    NSURL *albumURL = [GDataServiceGooglePicasaWeb
     picasaWebFeedURLForUserID:@"my.account" albumID:nil
     albumName:@"MyBestPhotos" photoID:nil kind:nil access:nil];
    
    // set a title and description for the new photo
    GDataTextConstruct *title, *desc;
    title = [GDataTextConstruct textConstructWithString:@"Sunset Photo"];
    desc = [GDataTextConstruct textConstructWithString:@"A nice day"];
    
    GDataEntryPhoto *newPhoto = [GDataEntryPhoto photoEntry];
    [newPhoto setTitle:title];
    [newPhoto setPhotoDescription:desc];
    
    // attach the photo data
    NSData *data = [NSData dataWithContentsOfFile:@"/SunsetPhoto.jpg"];
    [newPhoto setPhotoData:data];
    [newPhoto setPhotoMIMEType:@"image/jpeg"];
    
    // now upload it
    GDataServiceTicket *ticket;
    ticket = [service fetchPicasaWebEntryByInsertingEntry:newPhoto
     forFeedURL:albumURL
     delegate:self
     didFinishSelector:@selector(addPhotoTicket:finishedWithEntry:)
     didFailSelector:@selector(addPhotoTicket:failedWithError:)];
    

    Source: http://googlemac.blogspot.com/2007/06/picasa-web-albums-meets-google-data.html