簡體   English   中英

IOS Facebook SDK如何分享圖片,鏈接,文字?

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

我在ios應用程序中使用了最后一個facebook sdk,並且嘗試共享包含說明和鏈接的圖像。 我努力了

[FBDialogs presentShareDialogWithLink] 

但我無法在共享結果中看到我的描述文本。 我努力了

[FBDialogs presentShareDialogWithPhotoParams] 

但是FBPhotoParams的描述字段為“ onlyread”,並且我無法添加任何文本。 所以我放棄了各種fbdialogs,我嘗試了另一種應用程序:

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");
                                         }
                                     }];



}

現在這個方法不起作用,並返回一個錯誤:

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

我沒有共享權限,但用戶從未看到權限對話框...也許我必須將我的應用程序提交給Facebook,以獲取我的Facebook應用程序的“一般” ublish_actions權限? 它只是一個鏈接,我不想發送構建,等待批准,ecc ..現在分享圖像和文本的鏈接真的很復雜? 我想會有一個更簡單的解決方案......我該怎么辦?

用這個,

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM