Facebook iOS SDK: Cannot specify an album using FBRequest's requestForUploadPhoto:

青春壹個敷衍的年華 提交于 2019-11-29 00:16:45

Ahh SWEET. I figured this one out with some good old-fashioned, straight-up tinkering.

Given that there is no real instruction on how to apply the 'album' value to an FBRequest, I hesitate to call it a bug, but either way I needed a different method - in this case, simply creating a generic Open Graph HTTP request and filling in all the image info.

There is no real downside to this approach; except that you can't use the requestForUploadPhoto: convenience method.

Here is my implementation of the correct method (removed code is commented out):

- (void)postPhotosToFacebook:(NSArray *)photos withAlbumID:(NSString *)albumID {

    UIImage *image = [photos lastObject];

//    FBRequest *imageUploadRequest = [FBRequest requestForUploadPhoto:image];
//    
//    [[imageUploadRequest parameters] setValue:albumID
//                                       forKey:@"album"];
//    
//    DebugLog(@"imageUploadRequest parameters: %@",[imageUploadRequest parameters]);

    NSString *graphPath = [NSString stringWithFormat:@"%@/photos",albumID];

    DebugLog(@"graphPath = %@",graphPath);

    NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:
                                image,@"picture",
                                nil];

    FBRequest *request = [FBRequest requestWithGraphPath:graphPath
                                              parameters:parameters
                                              HTTPMethod:@"POST"];

    FBRequestConnection *connection = [[FBRequestConnection alloc] init];

    [connection addRequest:request
         completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

             if (!error) {

                 DebugLog(@"Photo uploaded successfuly! %@",result);

             } else {

                 DebugLog(@"Photo uploaded failed :( %@",error.userInfo);
             }

         }];

    [connection start];

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!