Post photo on user's wall using Facebook iOS SDK

后端 未结 5 594
南方客
南方客 2020-11-27 12:22

I\'m trying to upload a photo from the camera to a user\'s Facebook wall. I\'m not entirely sure what the correct strategy is, but from reading around it seems the thing to

5条回答
  •  生来不讨喜
    2020-11-27 13:25

    Using Facebook SDK 3.0:

     - (void)postPhotoThenOpenGraphAction {
        FBRequestConnection *connection = [[FBRequestConnection alloc] init];
    
        // First request uploads the photo.
        FBRequest *request1 = [FBRequest 
            requestForUploadPhoto:self.selectedPhoto];
        [connection addRequest:request1
            completionHandler:
            ^(FBRequestConnection *connection, id result, NSError *error) {
                if (!error) {
                }
            }
                batchEntryName:@"photopost"
        ];
    
        // Second request retrieves photo information for just-created 
        // photo so we can grab its source.
        FBRequest *request2 = [FBRequest 
            requestForGraphPath:@"{result=photopost:$.id}"];
        [connection addRequest:request2
             completionHandler:
            ^(FBRequestConnection *connection, id result, NSError *error) {
                if (!error &&
                    result) {
                    NSString *source = [result objectForKey:@"source"];
                    [self postOpenGraphActionWithPhotoURL:source];
                }
            }
        ];
    
        [connection start];
    }
    

    They follow this post with an OpenGraph action publish ([self postOpenGraphActionWithPhotoURL:source];), but if you just want the image on the user's wall, you wont need that.

    More info: https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/publish-open-graph-story/#step7

    Yay!, FB SDK 3.0 rocks! No more AppDelegate.facebook :)

提交回复
热议问题