1

现在,我正在尝试使用如下所示的 Objective 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: 方法

 if (error == nil) {
    NSLog(@"UPLOADED");
} else {
    NSLog(@"THERE WAS AN ERROR");
}

我不断收到“出现错误”,并且 failedWithStatus:400 数据:必须包含照片数据或源 ID。任何帮助是极大的赞赏。

谢谢。

4

1 回答 1

1

GooglePhotosSample应用程序所示,上传到相册的uploadLink. 不要尝试手动制作相册 URL 以进行上传。专辑 ID 不是专辑名称。

UIImageJPEGRepresentation很容易失败;检查它是否返回非零数据。

setPhotoData:和是和setPhotoMIMEType:的同义词;无需同时调用两者。setUploadData:setUploadMIMEType:

setTitle:setPhotoDescription:具有“WithString”版本,因此无需显式创建文本结构来设置它们。

启用库的http 日志记录以查看实际的服务器请求和响应。

于 2012-09-09T16:34:33.630 回答