0
    UIImage *image = [UIImage imageNamed:@"attachment_blank.png"];
    FBSDKSharePhoto *photo = [FBSDKSharePhoto photoWithImage:image userGenerated:NO];
NSDictionary *properties = @{
                               @"og:type": @"app:recipe",
                               @"og:title": @"Sample Recipe",
                               @"og:description": @"",
                               @"og:url": @"http://samples.ogp.me/216213502062059",
                               @"og:image": @[photo]
                           };
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
[shareAPI createOpenGraphObject:object];

提交指南谈到了“用户生成的照片”权限,该权限似乎在应用程序设置的任何地方或文档中的任何其他地方都不可用。这还需要吗?图片有类似的权限吗?

4

1 回答 1

0

您可以尝试使用此方法共享带有链接的图像。您要分享的图片需要在服务器上(即您需要使用图片的链接) 注意:- 您必须拥有来自 facebook 应用程序的“publish_actions”权限

以下方法使用 facebook sdk 4.3 显示

在 .h 文件中

#import <FacebookSDK/FacebookSDK.h>
@property (strong, nonatomic) FBRequestConnection *requestConnection;

在 .m 文件中

-(IBAction)facebookBtn:(id)sender{
    if (!FBSession.activeSession.isOpen) {
    // if the session is closed, then we open it here, and establish a handler for state changes
    [FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"email", @"user_events", @"user_location", @"publish_actions"]
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *session,
                                                      FBSessionState state,
                                                      NSError *error) {
                                if (error)
                                {
                                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Error", nil) message:error.localizedDescription delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];

                                          if (error.code!=2)
                                          {
                                              [alertView show];
                                          }

                                      }
                                      else if (session.isOpen)
                                      {

                                          [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                              [self requestCompleted:connection forFbID:@"me" result:result error:error];
                                          }];
                                                                                       // create the connection object
                                          FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];

                                          // create a handler block to handle the results of the request for fbid's profile
                                          FBRequestHandler handler =
                                          ^(FBRequestConnection *connection, id result, NSError *error) {
                                              // output the results of the request
                                              [self requestCompleted:connection forFbID:@"me" result:result error:error];
                                              [self showAlert:NSLocalizedString(@"Posted successfully", nil)];
                                          };

                                          // create the request object, using the fbid as the graph path
                                          // as an alternative the request* static methods of the FBRequest class could
                                          // be used to fetch common requests, such as /me and /me/friends
                                          NSString *messageString=[NSString stringWithFormat:NSLocalizedString(@"Just parked at %@ with #ParkHero", nil),@"miami"];
                                          NSString *imageUrl = @"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRFoE4FjiykSb-3usYJ6OuyUsa_NB0s0B13u52IKK80se0qOwPJ" ;
                                          // Your facebook application link
                                          NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"https://www.facebook.com/ParkHero?fref=ts", @"link",imageUrl, @"picture",messageString,@"message",nil];



                                          FBRequest *request=[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"me/feed" parameters:params HTTPMethod:@"POST"];


                                          [newConnection addRequest:request completionHandler:handler];

                                          // if there's an outstanding connection, just cancel
                                          [self.requestConnection cancel];

                                          // keep track of our connection, and start it
                                          self.requestConnection = newConnection;
                                          [newConnection start];
                                      }
                }];
}
else
{
    FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];

    // create a handler block to handle the results of the request for fbid's profile
    FBRequestHandler handler = ^(FBRequestConnection *connection, id result, NSError *error) {
        // output the results of the request
        [self requestCompleted:connection forFbID:@"me" result:result error:error];
        [self showAlert:NSLocalizedString(@"Posted successfully", nil)];
    };

    // create the request object, using the fbid as the graph path
    // as an alternative the request* static methods of the FBRequest class could
    // be used to fetch common requests, such as /me and /me/friends
    NSString *messageString=[NSString stringWithFormat:NSLocalizedString(@"Just parked at %@ with #ParkHero", nil),@"miami"];
    NSString *imageUrl = @"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRFoE4FjiykSb-3usYJ6OuyUsa_NB0s0B13u52IKK80se0qOwPJ";
// Your facebook application link
    NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"https://www.facebook.com/ParkHero?fref=ts", @"link",imageUrl, @"picture",messageString,@"message",nil];

    FBRequest *request=[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"me/feed" parameters:params HTTPMethod:@"POST"];
    [newConnection addRequest:request completionHandler:handler];

    // if there's an outstanding connection, just cancel
    [self.requestConnection cancel];

    // keep track of our connection, and start it
    self.requestConnection = newConnection;
    [newConnection start];
    }
}
于 2016-02-23T07:24:03.310 回答