【问题标题】:How does the uiwebview gets access token to like the facebookpage (through iFrame)?uiwebview 如何获得访问令牌以喜欢 facebookpage(通过 iFrame)?
【发布时间】:2012-08-27 14:35:04
【问题描述】:

在我的项目中,用户通过 Facebook 本地应用程序(FBConnect)登录,我保留了用户的访问令牌。在我的应用程序中,我有一个类似按钮,它显示 facebookpage 类似按钮的 iframe,现在当用户按下类似页面按钮时,facebook 要求用户再次登录。 尽管用户当前已登录并且令牌有效并且我正在 iframe 中传递访问令牌 这是我用于创建 iframe 的代码。

NSString *str=[NSString stringWithFormat:@"<iframe src=\"https://www.facebook.com/plugins/likebox.php?id=XXXXXXXXXXXXXXX&access_token=%@&amp;width=292&amp;connections=0&amp;stream=false&amp;header=false&amp;height=62\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:282px; height:62px;\" allowTransparency=\"true\"></iframe>",accesstoken];
NSString *likeButtonHtml = [NSString stringWithFormat:@"<HTML><BODY>%@</BODY></HTML>", str];
  [webview loadHTMLString:likeButtonHtml baseURL:[NSURL URLWithString:@""]];

请告诉我如何避免第二次登录像 iframe 上的页面

【问题讨论】:

  • 代码在哪里?如果这是一个关于 iframe 的问题,那么为什么问题会被标记为“iOS”和“Objective-C”?
  • @NSPostWhenIdle 我已经编辑了代码
  • 我和你有完全相同的问题,但使用的是 Android。但答案几乎是一样的:stackoverflow.com/questions/12464570/…

标签: objective-c ios facebook facebook-graph-api iframe


【解决方案1】:

您应该使用 UIWebView 登录。您可以使用实现方法来做到这一点:

[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
    switch (status) {
        case FBSessionStateOpen:
            // call the legacy session delegate
            //Now the session is open do corresponding UI changes
            break;
        case FBSessionStateClosedLoginFailed:
        { // prefer to keep decls near to their use

            // unpack the error code and reason in order to compute cancel bool
            NSString *errorCode = [[error userInfo] objectForKey:FBErrorLoginFailedOriginalErrorCode];
            NSString *errorReason = [[error userInfo] objectForKey:FBErrorLoginFailedReason];
            BOOL userDidCancel = !errorCode && (!errorReason ||
                                                [errorReason isEqualToString:FBErrorLoginFailedReasonInlineCancelledValue]);

            // call the legacy session delegate if needed
            //[[delegate facebook] fbDialogNotLogin:userDidCancel];
        }
            break;
            // presently extension, log-out and invalidation are being implemented in the Facebook class
        default:
            break; // so we do nothing in response to those state transitions
    }
}];

查看我的示例代码:https://github.com/gneil90/facebook-likebox-ios-login

【讨论】:

    猜你喜欢
    • 2016-04-03
    • 2013-02-16
    • 1970-01-01
    • 2018-06-13
    • 2013-04-03
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    相关资源
    最近更新 更多