在我的项目中,用户通过Facebook本机应用程序(FBConnect)登录,并保留了用户的访问令牌。在我的应用程序中,我有一个像按钮一样显示facebook页面的iframe按钮,现在当用户按下页面按钮时,facebook要求用户再次登录。 虽然用户当前已登录且令牌有效,但我在iframe中传递了访问令牌 这是我用来创建iframe的代码。
NSString *str=[NSString stringWithFormat:@"<iframe src=\"https://www.facebook.com/plugins/likebox.php?id=XXXXXXXXXXXXXXX&access_token=%@&width=292&connections=0&stream=false&header=false&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上的页面
答案 0 :(得分: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