Right now I am trying to upload a photo to Picasa using the objective c client like below:
GDataServiceGooglePhotos* service =
[self photoService];
// get the URL for the album
NSURL *albumURL = [GDataServiceGooglePhotos
photoFeedURLForUserID:userEmailAdress albumID:albumName
albumName:nil photoID:nil kind:@"album" access:@"all"];
// set a title and description for the new photo
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateFormat = @"yyyyMMddHHmmssSSSS";
GDataTextConstruct *title, *desc;
title = [GDataTextConstruct textConstructWithString:[df stringFromDate:[NSDate date]]];
desc = [GDataTextConstruct textConstructWithString:[descriptionTextfield text]];
GDataEntryPhoto *newPhoto = [GDataEntryPhoto photoEntry];
[newPhoto setTitle:title];
[newPhoto setPhotoDescription:desc];
// attach the photo data
NSData *data = UIImageJPEGRepresentation(imageView.image, 1.0);
[newPhoto setPhotoData:data];
[newPhoto setPhotoMIMEType:@"image/jpeg"];
[newPhoto setUploadData:data];
[newPhoto setUploadMIMEType:@"image/jpeg"];
[newPhoto setUploadSlug:title.stringValue];
// now upload it
GDataServiceTicket *ticket;
ticket = [service fetchEntryByInsertingEntry:newPhoto forFeedURL:albumURL delegate:self didFinishSelector:@selector(addPhotoTicket:finishedWithEntry:error:)];
[service setServiceUploadProgressSelector:nil];
And here is my addPhotoTicket:finishedWithEntry:error: method
if (error == nil) {
NSLog(@"UPLOADED");
} else {
NSLog(@"THERE WAS AN ERROR");
}
I keep getting “There was an error”, and failedWithStatus:400 data:Photo data or source id must be included. Any help is greatly appreciated.
Thanks.
As shown in the GooglePhotosSample application, uploading should be done to the URL of an album’s
uploadLink. Don’t try to make an album URL manually for uploading. The album ID is not the album’s name.UIImageJPEGRepresentationcan easily fail; check that it is returning non-nil data.setPhotoData:andsetPhotoMIMEType:are synonyms forsetUploadData:andsetUploadMIMEType:; there is no need to call both.setTitle:andsetPhotoDescription:have “WithString” versions so there’s no need to create a text construct explicitly to set those.Enable the library’s http logging to see the actual server requests and responses.