Gdata objective-c上传照片错误必须设置400张照片数据(picasa)

时间:2012-09-09 02:29:53

标签: objective-c ios ios5 gdata

目前我正在尝试使用下面的客观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。非常感谢任何帮助。

感谢。

1 个答案:

答案 0 :(得分:1)

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

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

setPhotoData:setPhotoMIMEType:setUploadData:setUploadMIMEType:的同义词;没有必要同时打电话。

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

启用库的http logging以查看实际的服务器请求和响应。