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

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

问题描述

我正在使用下面的代码发贴到Facebook。它工作正常,但是当我用 myapp:// test_page // 替换 MY_URL 时,该帖子不会显示在Facebook时间轴中。



如果我做错了,请告诉我如何将我的应用程序深入链接到Facebook应用程序。我搜索了几乎所有的stackoverflow.com页面和其他Facebook开发人员教程,但我不明白。

  NSMutableDictionary * params = [NSMutableDictionary dictionaryWithCapacity:0]; 
[params setObject:@查看我在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参数:params HTTPMethod:@POST
completionHandler:^(FBRequestConnection * connection,id result,NSError * error){
NSLog(@FACEBOOK DONE);
}];


解决方案

感谢您的回答@Jo Govindani,比你的答案简单我从Facebook的文档中发现了这一点。



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





我在应用程序的设置中添加了Bundle标识符。并启用 Facebook深度链接
当然,我还需要 App Store ID



并用 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);
返回;

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

//将对话框参数

NSArray * actionLinks = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
@Scisser,@名称,
@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];

//发出请求
[FBRequestConnection startWithGraphPath:@/ me / feed
参数:params
HTTPMethod:@POST
completionHandler :^(FBRequestConnection * connection,id result,NSError * error){
if(!error)
{
//链接成功发送到Facebook

[self alertshowWithTitle:@恭喜消息:@发布已成功在您的Facebook时间线上共享。];

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

completionBlock(YES);
返回;
}
else
{
//发生错误,我们需要处理错误
//参见:https://developers.facebook.com/docs / ios / errors
NSLog(@%@,[NSString stringWithFormat:@%@,error.description]);

completionBlock(NO);
返回;
}
}];

}
}];
}


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.

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

解决方案

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

First i changes App settings in Facebook account:

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

And wrote the below method with 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天全站免登陆