简体   繁体   中英

Share image to Facebook from iOS/Android using Facebook API in Unity3D

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM