Facebook 与 iOS 应用程序的深度链接 [英] Facebook deep linking with iOS app

查看:29
本文介绍了Facebook 与 iOS 应用程序的深度链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码发布到 Facebook.它运行良好,但是当我用 myapp://test_page// 替换 MY_URL 时,该帖子不会出现在 Facebook 时间轴中.

I am using below code to post to Facebook. It is working perfectly but when i replace MY_URL with myapp://test_page// the post won't appear in Facebook timeline.

如果我做错了什么,请告诉我如何将我的应用深层链接到 Facebook 应用.我已经搜索了几乎所有 stackoverflow.com 页面 &其他 Facebook 开发者教程,但我无法理解.

If i'm doing something wrong then please tell me how can i deep-link my app to Facebook app. I've searched almost all stackoverflow.com pages & other Facebook developer tutorials but i can not understand that.

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
[params setObject:@"Check out my post in myapp" forKey:@"message"];
[params setObject:MY_URL forKey:@"link"];
[params setObject:MY_IMAGE_URL forKey:@"picture"];
[params setObject:self.strQuestion forKey:@"name"];
[params setObject:@"" forKey:@"caption"];
[params setObject:self.strDescription forKey:@"description"];

[FBRequestConnection startWithGraphPath:@"me/feed" parameters:params HTTPMethod:@"POST"
 completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
     NSLog(@"FACEBOOK DONE");
 }];

推荐答案

感谢@Jai Govindani 的回答,但这比您的回答简单得多.这是我从 Facebook 文档中发现的.

Thanks for answer @Jai Govindani, but it was much simpler than your answer. I found out this from Facebook documentations.

首先我更改 Facebook 帐户中的应用设置:

First i changes App settings in Facebook account:

我在应用的设置中添加了捆绑标识符.并启用 Facebook 深层链接当然,我还需要App store ID"

I added Bundle identifier in app's settings. And enabled Facebook deep linking And of course, i also needed "App store ID"

并使用 completionBlock -

- (void)shareOnFacebookWithName:(NSString *)strName withDescription:(NSString *)strDesc withLink:(NSString *)strLink WithPictureLink:(NSString *)strPicLink withCaption:(NSString *)strCaption withCompletionBlock:(shareCompletion)completionBlock
{
    __block NSString *strLinkBlock = strLink;

    [FBSession openActiveSessionWithPublishPermissions: [NSArray arrayWithObjects: @"publish_stream", nil] defaultAudience: FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler: ^(FBSession *session,FBSessionState status,NSError *error)
     {
         if (error)
         {
             completionBlock(NO);
             return;

             NSLog(@"error");
         }
         else
         {
             [FBSession setActiveSession:session];
             NSLog(@"LOGIN SUCCESS");

             // Put together the dialog parameters

             NSArray* actionLinks = [NSArray arrayWithObjects:
                                     [NSDictionary dictionaryWithObjectsAndKeys:
                                      @"Scisser",@"name",
                                      @"http://m.facebook.com/apps/uniquenamespace/",@"link",
                                      nil],
                                     nil];

             NSString *actionLinksStr = [actionLinks JSONRepresentation];

             if (strLink.length == 0)
             {
                 strLinkBlock = @"http://www.scisser.com";
             }

             NSString *strDescription = strDesc;
             if (!strDescription)
             {
                 strDescription = @"";
             }

             NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                            strName, @"name",
                                            strCaption, @"caption",
                                            strDescription, @"description",
                                            strLinkBlock, @"link",
                                            strPicLink, @"picture",
                                            @"foo", @"ref",
                                            actionLinksStr, @"actions",
                                            nil];

             // Make the request
             [FBRequestConnection startWithGraphPath:@"/me/feed"
                                          parameters:params
                                          HTTPMethod:@"POST"
                                   completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                       if (!error)
                                       {
                                           // Link posted successfully to Facebook

                                           [self alertshowWithTitle:@"Congratulations" message:@"Post was successfully shared on your Facebook timeline."];

                                           NSLog(@"%@",[NSString stringWithFormat:@"result: %@", result]);

                                           completionBlock(YES);
                                           return;
                                       }
                                       else
                                       {
                                           // An error occurred, we need to handle the error
                                           // See: https://developers.facebook.com/docs/ios/errors
                                           NSLog(@"%@",[NSString stringWithFormat:@"%@", error.description]);

                                           completionBlock(NO);
                                           return;
                                       }
                                   }];

         }
     }];
}

这篇关于Facebook 与 iOS 应用程序的深度链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆