简体   繁体   中英

Ios Facebook SDK how i can share an image,a link,a text?

I'm using the last facebook sdk in my ios app and i'm trying to share an image with a description and a link. I have tried

[FBDialogs presentShareDialogWithLink] 

but i can't see my description text in the shared result. I have tried

[FBDialogs presentShareDialogWithPhotoParams] 

but the description field of the FBPhotoParams is "onlyread" and i can't add any text. So i have abandoned the various fbdialogs and i have tried something that works in another my app:

if ([[FBSession activeSession] isOpen]) {
    /*
     * if the current session has no publish permission we need to reauthorize
     */
    if ([[[FBSession activeSession] permissions]indexOfObject:@"publish_actions"] == NSNotFound) {

        [[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends
                                              completionHandler:^(FBSession *session,NSError *error){
                                                  [self share];
                                              }];

    }else{
        [self share];
    }
}else{
    /*
     * open a new session with publish permission
     */

    [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                       defaultAudience:FBSessionDefaultAudienceOnlyMe
                                          allowLoginUI:YES
                                     completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
                                         if (!error && status == FBSessionStateOpen) {
                                             [self share];
                                         }else{
                                             NSLog(@"error");
                                         }
                                     }];



}

Now this method not working and return me an error:

"OAuth \"Facebook Platform\" \"insufficient_scope\" \"(#200) The user hasn't authorized the application to perform this action\"";

I haven't the permission to share, but the user never see the permission dialog...Maybe i have to submit my application to Facebook for achive a "general" ublish_actions permission for my facebook app? It's only a link, i don't wanna send a build, wait an approvation,ecc.. Now it's really so complicated to share a link with an image and a text? There will be a simpler solution , i think... How i can do?

use this,

NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   name, @"name",
                                   author, @"caption",
                                   linkShare, @"link",
                                   userImage, @"picture",
                                   nil];

[FBWebDialogs presentFeedDialogModallyWithSession:nil
                                       parameters:parameter
                                          handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                              if (error)
                                              {
                                                  NSLog(@"Error publishing story: %@", error.description);
                                              }
                                              else
                                              {
                                                  if (result == FBWebDialogResultDialogNotCompleted)
                                                  {
                                                      NSLog(@"User cancelled.");
                                                  }
                                                  else
                                                  {
                                                      NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
                                                      NSLog(@"User login");

                                                      if (![urlParams valueForKey:@"post_id"])
                                                      {
                                                          NSLog(@"User cancelled post.");

                                                      }
                                                      else
                                                      {
                                                          NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
                                                          NSLog(@"result %@", result);

                                                      }
                                                  }
                                              }
                                         }];    


- (NSDictionary*)parseURLParams:(NSString *)query
{

    NSArray *pairs = [query componentsSeparatedByString:@"&"];
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    for (NSString *pair in pairs)
    {
        NSArray *kv = [pair componentsSeparatedByString:@"="];
        NSString *val = [kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        params[kv[0]] = val;
    }
    return params;
}

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