【问题标题】:Facebook Comments Widget in iOS App with native authorizationiOS App 中的 Facebook 评论小部件,具有本机授权
【发布时间】:2015-08-25 07:57:15
【问题描述】:

我正在尝试在 iOS 应用程序中嵌入 Facebook cmets 小部件,该应用程序已获得 Facebook 授权。

我可以使用用户的访问令牌在 UIWebView 中设置适当的 cookie 吗?

- (void)loadComments {
    [_webView loadHTMLString:(@"<!DOCTYPE html>\n"
            "<html>\n"
            "<head>\n"
            "\t<title></title>\n"
            "</head>\n"
            "<body>\n"
            "<div id=\"fb-root\"></div>\n"
            "<script>(function(d, s, id) {\n"
            "  var js, fjs = d.getElementsByTagName(s)[0];\n"
            "  if (d.getElementById(id)) return;\n"
            "  js = d.createElement(s); js.id = id;\n"
            "  js.src = \"http://connect.facebook.net/en-US/sdk.js#xfbml=1&version=v2.4&appId=appId\";\n"
            "  fjs.parentNode.insertBefore(js, fjs);\n"
            "}(document, 'script', 'facebook-jssdk'));</script>\n"
            "<div class=\"fb-comments\" data-href=\"myUrl\" data-width=\"375\" data-numposts=\"20\"></div>\n"
            "</body>\n"
            "</html>") baseURL:[[NSURL alloc] initWithString:(@"https://myUrl")]];
}

#pragma mark - UIWebViewDelegate

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    //Maybe there is a better way to check auth redirect?
    if ([[request.URL absoluteString] containsString:(@"login")]) {
        [_webView loadHTMLString:(@"") baseURL:nil];
        FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
        [login logInWithReadPermissions: @[(@"public_profile")]
                                handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
                                     if (error) {

                                     } else if (result.isCancelled) {

                                     } else {
                                         //Here I need to set cookies, or something like that
                                         [self loadComments];
                                     }
                                 }];
        return NO;
    }
    else {
        return YES;
    }
}

我看到了这个问题,但建议的答案无法通过本机/facebook 应用验证:FBConnect login, share with a webview?

我知道,我可以使用 GraphAPI,但我现在不想实现整个 cmets 逻辑和 UI。

【问题讨论】:

    标签: ios facebook-graph-api uiwebview facebook-ios-sdk facebook-social-plugins


    【解决方案1】:

    除此之外,您还可以使用 iOS SDK 的社交框架。实现起来非常简单。

    但用户应该已经在 iOS 设置中登录了 fb。

    【讨论】:

    • 有什么方法可以使用 Social Framework 来检索和发布 Facebook cmets?
    猜你喜欢
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    • 2015-08-07
    • 2018-11-17
    • 1970-01-01
    相关资源
    最近更新 更多