目前我正在尝试使用下面的客观c客户端将照片上传到Picasa:
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];
这是我的addPhotoTicket:finishedWithEntry:error:method
if (error == nil) {
NSLog(@"UPLOADED");
} else {
NSLog(@"THERE WAS AN ERROR");
}
我一直收到“有错误”,并且失败了状态:400数据:必须包含照片数据或来源ID。非常感谢任何帮助。
感谢。
答案 0 :(得分:1)
如GooglePhotosSample应用程序所示,应上传到相册uploadLink
的网址。请勿尝试手动制作相册网址以进行上传。专辑ID不是专辑的名称。
UIImageJPEGRepresentation
很容易失败;检查它是否返回非零数据。
setPhotoData:
和setPhotoMIMEType:
是setUploadData:
和setUploadMIMEType:
的同义词;没有必要同时打电话。
setTitle:
和setPhotoDescription:
具有“WithString”版本,因此无需明确创建文本构造来设置它们。
启用库的http logging以查看实际的服务器请求和响应。