简体   繁体   English

如何在Facebook iPhone 6中共享带有图像和描述的链接

[英]How to share a link with image and description in facebook iPhone 6

    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];

The submission guidelines speak about a "user generated photos" permission that doesn't seem to be available anywhere in the app settings, or anywhere else in the documentation. 提交准则涉及“用户生成的照片”权限,该权限似乎在应用程序设置中的任何地方或文档中的其他任何地方都不可用。 Is that still required? 还需要吗? Is there a similar permission for images? 有类似的图片许可吗?

You can try this method to share an image with link. 您可以尝试使用此方法与链接共享图像。 The image you want to share should need to be on server(ie you need to use link of an image ) Note:- You must have an "publish_actions" permission from facebook app 您要共享的图像应该在服务器上(即,您需要使用图像的链接)注:-您必须具有facebook应用程序的“ publish_actions”权限

Below method is shown using the facebook sdk 4.3 使用facebook sdk 4.3显示以下方法

In .h file 在.h文件中

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

In .m file 在.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];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从捆绑中共享图像并在iPhone中的Facebook上链接 - Share image from bundle and link on Facebook in iphone Facebook分享:在Facebook iPhone应用程序中看不到描述 - facebook share: description not visible in facebook iphone app 如何在iPhone SDK中使用UIDocumentInteractionController共享图像,文本和链接 - How to share image, text and link using UIDocumentInteractionController in iPhone sdk IOS Facebook SDK如何分享图片,链接,文字? - Ios Facebook SDK how i can share an image,a link,a text? 从iPhone发布到墙上时,如何在Facebook描述字段中插入链接? - how to insert link in facebook description field when posting to wall from iphone? 在iphone的facebook墙上分享图片和文字不起作用? - Share Image and text on facebook wall in iphone is not working? iOS 8 Facebook共享链接,图像和文本 - iOS 8 Facebook share link, image and text Facebook分享扩展,分享图片和链接 - Facebook share extension, sharing image and link 如何在Iphone中共享图像和文本 - How to share Image and text in Iphone 如何通过 Facebook 移动应用程序在 Flutter 应用程序中与用户管理的 Facebook 页面共享链接(或图像) - How to share link (or image) with quote to a Facebook Page managed by the user in a Flutter app via Facebook mobile app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM