Facebook iOS SDK:无法使用FBRequest的requestForUploadPhoto指定相册:

tob*_*pwn 6 facebook facebook-graph-api ios facebook-ios-sdk

我的iPhone应用程序中有本地照片,我想将其上传到专用于我的应用程序的Facebook上的特定相册.

问题:我的应用名称以"照片"结尾,因此默认的Facebook相册APP_NAME Photos Photos显然是个问题.

目标:我想创建一个新专辑,将其ID存储在其中NSUserDefaults,并且(在运行时进行一些验证后)将其用于从应用程序上传的所有未来照片.

我在哪里:我可以通过Open Graph制作新专辑,使用我想要的名称和描述,我可以检索其ID.我也可以轻松上传照片.但是,我无法弄清楚如何指定上传照片的最终位置!

代码:这是我的照片上传代码,其中包含一些结果.我假设这是我的问题所在,因为专辑创建等工作正常.

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

    // Just testing with one image for now; I'll get in to multiple later..
    UIImage *image = [photos lastObject];

    FBRequest *imageUploadRequest = [FBRequest requestForUploadPhoto:image];

    // CALL OUT: I'm guessing my problem is here - but I just don't know!
    [[imageUploadRequest parameters] setValue:albumID
                                       forKey:@"album"];

    DebugLog(@"imageUploadRequest parameters: %@",[imageUploadRequest parameters]);

    // Results of DebugLog:
    // imageUploadRequest parameters: {
    //     album = 10151057144449632;
    //     picture = "<UIImage: 0xc6b6920>";
    // }
    // The album data returns correctly using FB's Graph API explorer tool,
    // so I know it's a legit album.
    // https://developers.facebook.com/tools/explorer

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

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

             if (!error) {

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

                 // Results of DebugLog:
                 // 
                 // Photo uploaded successfuly! {
                 //     id = 10151057147399632;
                 //     "post_id" = "511304631_10151057094374632";
                 // }
                 // Again, the photo at that ID shows up correctly, etc -
                 // BUT it's in the wrong album! It shows up in the default app album.

             } else {

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

         }];

    [connection start];

}
Run Code Online (Sandbox Code Playgroud)

猜测:我猜我的问题在于如何将我的相册ID参数分配给图像请求..但我不知道.

你可以在这个URL看到这应该是可能的..

tob*_*pwn 6

啊,SWEET.我认为这是一个很好的老式,直接的修修补补.

鉴于没有关于如何将"专辑"值应用于FBRequest的实际指令,我不愿意将其称为错误,但无论哪种方式,我都需要一种不同的方法 - 在这种情况下,只需创建一个通用的Open Graph HTTP请求和填写所有图像信息.

这种方法没有真正的缺点; 除了你不能使用requestForUploadPhoto:方法.

这是我正确方法的实现(删除的代码被注释掉):

- (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];

}
Run Code Online (Sandbox Code Playgroud)