首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在facebook iPhone 6中分享带有图片和描述的链接

如何在facebook iPhone 6中分享带有图片和描述的链接
EN

Stack Overflow用户
提问于 2016-02-23 14:39:36
回答 1查看 183关注 0票数 0
代码语言:javascript
复制
    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];

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

EN

回答 1

Stack Overflow用户

发布于 2016-02-23 15:24:03

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

下面的方法使用facebook sdk 4.3显示

在.h文件中

代码语言:javascript
复制
#import <FacebookSDK/FacebookSDK.h>
@property (strong, nonatomic) FBRequestConnection *requestConnection;

在.m文件中

代码语言:javascript
复制
-(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];
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35570539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档