Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone Objective-C Google Web Albums API-尝试上载图像时出现奇怪错误_Iphone_Objective C_Gdata_Picasa - Fatal编程技术网

Iphone Objective-C Google Web Albums API-尝试上载图像时出现奇怪错误

Iphone Objective-C Google Web Albums API-尝试上载图像时出现奇怪错误,iphone,objective-c,gdata,picasa,Iphone,Objective C,Gdata,Picasa,我使用的是Objective-C版本的API 我几乎完全复制了示例项目中的代码,但是 每次尝试上载图片时都会出现此错误: “failedWithStatus:400数据:照片数据不能为空。” 这是我的密码: - (void)uploadToPicasa { // make a new entry for the photo GDataEntryPhoto *newEntry = [GDataEntryPhoto photoEntry]; // set a title, de

我使用的是Objective-C版本的API

我几乎完全复制了示例项目中的代码,但是 每次尝试上载图片时都会出现此错误: “failedWithStatus:400数据:照片数据不能为空。”

这是我的密码:

- (void)uploadToPicasa
{

   // make a new entry for the photo
   GDataEntryPhoto *newEntry = [GDataEntryPhoto photoEntry];

   // set a title, description, and timestamp
   [newEntry setTitleWithString:@"Title!"];
   [newEntry setPhotoDescriptionWithString:@"Description!"];
   [newEntry setTimestamp:[GDataPhotoTimestamp timestampWithDate:
[NSDate date]]];

   // attach the NSData and set the MIME type for the photo
   UIImage *earth_image = [UIImage imageNamed:@"earth.jpg"];
   NSData *earth_data = UIImageJPEGRepresentation(earth_image, 1.0);

   [newEntry setPhotoData:earth_data];

   NSString *mimeType = @"image/jpeg";

   [newEntry setPhotoMIMEType:mimeType];

   // the slug is just the upload file's filename
   [newEntry setUploadSlug:@"earth.jpg"];

   // make service tickets call back into our upload progress
selector
   GDataServiceGooglePhotos *service = [self googlePhotosService];

   SEL progressSel =
@selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
   [service setServiceUploadProgressSelector:progressSel];

   // Get URL for Picasa
   NSURL *uploadURL = [GDataServiceGooglePhotos
photoFeedURLForUserID:@"CORRECT_USERNAME"

albumID:nil

albumName:nil

photoID:nil

kind:nil

access:nil];

   // insert the entry into the album feed
   GDataServiceTicket *ticket;
   ticket = [service fetchEntryByInsertingEntry:newEntry
                                     forFeedURL:uploadURL
                                       delegate:self

didFinishSelector:@selector(addPhotoTicket:finishedWithEntry:error:)];

   // no need for future tickets to monitor progress
   [service setServiceUploadProgressSelector:nil];
}

// progress callback
- (void)ticket:(GDataServiceTicket *)ticket
hasDeliveredByteCount:(unsigned long long)numberOfBytesRead
ofTotalByteCount:(unsigned long long)dataLength {

   NSLog([NSString stringWithFormat:@"%d", numberOfBytesRead /
dataLength]);
}

// photo add callback
- (void)addPhotoTicket:(GDataServiceTicket *)ticket
    finishedWithEntry:(GDataEntryPhoto *)photoEntry
                error:(NSError *)error {

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

- (GDataServiceGooglePhotos *)googlePhotosService {

   static GDataServiceGooglePhotos* service = nil;

   if (!service) {
       service = [[GDataServiceGooglePhotos alloc] init];

       [service setShouldCacheResponseData:YES];
       [service setServiceShouldFollowNextLinks:YES];
   }

   // update the username/password each time the service is requested
   NSString *username = @"CORRECT_USERNAME";
   NSString *password = @"CORRECT_PASSWORD";
   if ([username length] && [password length]) {
       [service setUserCredentialsWithUsername:username
                                      password:password];
   } else {
       [service setUserCredentialsWithUsername:nil
                                      password:nil];
   }

   return service;
}
我使用了一个断点来确认NSData不是nil,而是 图像有问题,所以我不确定是什么“失败”与Status:400
数据:照片数据不能为空。”这可能意味着。请帮忙

而不是使用以下方法:

 NSURL *albumURL = [GDataServiceGooglePhotos
                       photoFeedURLForUserID:username albumID:kGDataGooglePhotosDropBoxAlbumID
                       albumName:nil photoID:nil kind:nil access:nil];
//要获取相册url,请使用此url:

NSURL *albumURL =
[NSURL URLWithString:kGDataGooglePhotosDropBoxUploadURL]
//在哪里

kGDataGooglePhotosDropBoxUploadURL = "https://photos.googleapis.com/data/upload/resumable/media/create-session/feed/api/user/default/albumid/default";
我尝试了我的应用程序,它的工作完美


您也可以在GDataAPI中找到此url。

您可以给我发送代码吗。我甚至不知道从哪里开始。尝试了很多样本,但有些丢失了一个文件,另一些丢失了另一个文件。急需这个,请帮助。这是太旧的代码,现在这个api已被弃用。。。你需要在与api集成后使用新的api上传照片你可以使用相同的url上传照片可能是..我可以通过Google plus api进行身份验证登录并获取用户名,但我无法获取用于上传的客户端密码和密钥。我已经完成了Oauth,正在获取Oauth对象。现在我必须上载图像,但我不希望用户输入他们的用户名和密码“[service SetUserCredentials WithUserName:uname password:pwd]”,因为他们已经通过Oauth。有什么替代方法可以做到这一点?有人可以给我发送代码吗。我甚至无法启动,因为我得到了Mac支持而不是iOS的代码。另外,我不理解谷歌API的集成。