IOS Facebook SDK 3 upload image with message

前端 未结 3 1878

I am using the following code to upload an image to Facebook wall :

UIImage *img = [UIImage imageNamed:@\"logoits.png\"];

[FBRequestConnection startForUploa         


        
相关标签:
3条回答
  • 2020-12-24 15:14

    In the Facebook SDK 3.0 only a image can be post using the given methods, and for other actions you need to use graph a pi's.

    So for post a image with message you need to use graph-api. Here is the line of codes which lets you to post a image with message on users timeline.

    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
    [params setObject:@"your custom message" forKey:@"message"];
    [params setObject:UIImagePNGRepresentation(_image) forKey:@"picture"];
    _shareToFbBtn.enabled = NO; //for not allowing multiple hits
    
    [FBRequestConnection startWithGraphPath:@"me/photos"
                                     parameters:params
                                     HTTPMethod:@"POST"
                              completionHandler:^(FBRequestConnection *connection,
                                                  id result,
                                                  NSError *error) 
     {
         if (error) 
         {
             //showing an alert for failure
             [self alertWithTitle:@"Facebook" message:@"Unable to share the photo please try later."];
         } 
         else
         {
             //showing an alert for success
             [UIUtils alertWithTitle:@"Facebook" message:@"Shared the photo successfully"];
         }
         _shareToFbBtn.enabled = YES;
     }];
    

    and also make sure _shareToFbBtn is enabled only after login is success.

    0 讨论(0)
  • 2020-12-24 15:25

    linesvishy's solution works great and it's also worth to note that if you were using Facebook SDK 3.1 and you used method

    FBRequest *request = [FBRequest requestForUploadPhoto:_imageToShare];
    

    You can just use the following lines to replace it:

    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
    [params setObject:_textToShare forKey:@"message"];
    [params setObject:_imageToShare forKey:@"picture"];
    FBRequest *request = [FBRequest requestWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST"];
    

    Hope it helps! Happy Coding!

    0 讨论(0)
  • 2020-12-24 15:31

    Here is an example that posts and image and a note:

    http://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/publish-open-graph-story/

    0 讨论(0)
提交回复
热议问题