【问题标题】:In Facebook share I am unable to post name, linkDescription and picture on FBLinkShareParams on Facebook app installed condition在 Facebook 分享中,我无法在 Facebook 应用安装条件上的 FBLinkShareParams 上发布名称、链接描述和图片
【发布时间】:2015-05-28 11:54:16
【问题描述】:

我想在 FBLinkShareParams 上发布名称、链接描述和图片,但我无法在 已安装 Facebook 应用 条件下执行此操作,但它在 未安装 Facebook 应用 条件下工作正常当它在 FBWebDialogs 中完成时。我只能在 Facebook 应用已安装 条件下发布 params.link

我使用的代码如下所示:

      #pragma mark - facebook share
    //facebook share
    - (void)shareLinkinFB{
    /* Facebook app is installed*/
        FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
        params.link = [NSURL URLWithString:@"https://developers.facebook.com/docs/ios/share/"];
        params.name= @"Dieheart";
        params.picture= [NSURL URLWithString:Str_KoolkatPic];
        params.linkDescription=@"A quick and better way to get anything delivered at your doorstep. ";



        // If the Facebook app is installed and we can present the share dialog
        if ([FBDialogs canPresentShareDialogWithParams:params]) {
            [FBDialogs presentShareDialogWithLink:params.link handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {    if(error) {
                // An error occurred, we need to handle the error
                NSLog(@"Error publishing story: %@", error.description);
            } else {
                // Success
                NSLog(@"result %@", results);
            }
            }];
            NSLog(@"Share login page Now");


        } else {
            /* Facebook app Not installed*/
            NSLog(@"Share dialog");
            NSString *urlString = [NSString stringWithFormat:@"%@/resources/images/login-logo.png",SERVER_ADDRESS];
            NSString *Str_NameLabel;
            NSString *Str_Description;
            Str_NameLabel=@"testing for idelivery IOS application";
            Str_Description=@"Share functionality in progress";

            NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                           Str_NameLabel, @"name",
                                           @"idelivery Town center", @"caption",
                                           Str_Description, @"description",
                                           @"https://www.facebook.com/edeliveryksa", @"link",
                                           urlString, @"picture",
                                           nil];
            // Show the feed dialog
            [FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params
                                                      handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                                          if (error) {
                                                              // An error occurred, we need to handle the error
                                                              // See: https://developers.facebook.com/docs/ios/errors
                                                              NSLog(@"Error publishing story: %@", error.description);
                                                          } else {
                                                              if (result == FBWebDialogResultDialogNotCompleted) {
                                                                  // User cancelled.
                                                                  NSLog(@"User cancelled.");
                                                              } else {
                                                                  // Handle the publish feed callback
                                                                  NSDictionary *urlParams = [self parseURLParams:[resultURL query]];

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

                                                                  } else {
                                                                      // User clicked the Share button
                                                                      NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
                                                                      NSLog(@"result %@", result);
                                                                      [self postSuccess]; // success vako condn ko lagi banako
                                                                  }
                                                              }
                                                          }
                                                      }];
        }}



    - (BOOL)application:(UIApplication *)application
                openURL:(NSURL *)url
      sourceApplication:(NSString *)sourceApplication
             annotation:(id)annotation {

        BOOL urlWasHandled = [FBAppCall handleOpenURL:url
                                    sourceApplication:sourceApplication
                                      fallbackHandler:^(FBAppCall *call) {
                                          NSLog(@"Unhandled deep link: %@", url);
                                          // Here goes the code to handle the links
                                      }];

        return urlWasHandled;
    }

    // A function for parsing URL parameters returned by the Feed Dialog.
    - (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;
    }


    - (void)postSuccess{

        NSLog(@" post success");
    }

希望有人能帮助我

【问题讨论】:

    标签: ios objective-c facebook facebook-share


    【解决方案1】:

    看起来您正在使用真正的参数调用canPresentShareDialogWithParams:,但在实际呈现对话框时,您使用nil 链接调用它,这可能就是没有显示的原因。

    您应该使用您创建的参数调用presentShareDialogWithParams:clientState:handler: 方法。

    [FBDialogs presentShareDialogWithParams:params 
                                clientState:nil
                                    handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {...}];
    

    【讨论】:

    • 检查我编辑的帖子。我在安装 Facebook 应用时遇到问题 我无法发布其他只能发布网址
    • 安装 Facebook 应用程序时,我无法在 FBLinkShareParams 上发布名称、链接描述和图片,但未安装 Facebook 应用程序时我可以发布
    • 请使用我在回答中提到的方法。您只使用 presentShareDialogWithLink: 方法,所以它当然只会共享链接,因为您没有将任何其他信息(如描述或图片)传递给该方法。
    • 我不知道该怎么做,你可以通过编辑我的帖子或你想要的来帮助我。如果你能帮助我,我会很高兴
    • 我对你的努力投了赞成票,希望我的问题也能得到同样的结果
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-26
    • 2012-05-18
    相关资源
    最近更新 更多