1

I am using Facebook SDK plugin for social sharing in my app.

I am able to logged in and sharing photos on user wall.

I want to upload that image on the Facebook which I have created from facebook account. Is there is Facebook API for sharing image on the facebook page.

Please help, for example my facebook page Url is https://www.facebook.com/demoneptune/ Thanks.

1

1 Answer 1

1

You need some permissions from facebook, most important permission is "publish_actions".

You need page_ID of that facebook page to which you want to post.

Then try this:

NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:@"Your own message" forKey:@"message"];
[params setObject:@"facebook_page_id_path_string" forKey:@"place"];

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/feed" parameters:params HTTPMethod:@"POST"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(@"result %@",result);
NSLog(@"error %@",error);
if (!error) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Posted!" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    [alert show];
     double delayInSeconds = 1.0;
     dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
     dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [alert dismissWithClickedButtonIndex:0 animated:YES];
     });
  } else {
      NSString *message = @"There was a problem sharing. Please try again!";
      [[[UIAlertView alloc] initWithTitle:nil message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
  }
}];

Hope this helps.

5
  • thanks ... what is the "place" key?? (BTW this is for Unity3D, not objC :) But the code is basically the same, thanks.)
    – Fattie
    Jul 7, 2016 at 12:19
  • its usually said to use "me/photos". What is the difference with "me/feed'? Thanks...
    – Fattie
    Jul 7, 2016 at 12:20
  • 1
    I've came through the same requirement and worked on many ways(publish_stream, me/feed, ...). There is a demo graph API in developers.facebook.com. There i came to know about "me/feed". It worked and I've followed it @Joe Blow.
    – Satish A
    Jul 7, 2016 at 12:26
  • good one @satishA, with me/feed does it end up on the user's "wall" ? Thanks.
    – Fattie
    Jul 7, 2016 at 12:46
  • 1
    with me/feed and page_id, it is posted to that page. But according to facebook, if user's post to any other users wall/pages, it also end up on his/her wall too @Joe Blow.
    – Satish A
    Jul 7, 2016 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.