Sharekit for Facebook(Graph API 版本)注销方法未完全注销或取消用户授权

发布于 2024-12-09 14:33:44 字数 458 浏览 0 评论 0原文

我正在使用 Sharekit 通过 Facebook Graph API 进行 Facebook 共享。我试图找到最新的、最新的代码(github 上的 troppoli 似乎是最新的)。

使用 sharekit 注销 Twitter 可以很好地使用以下行: [SHK logoutOfService:@"SHKTwitter"];但 Facebook 的同一行 [SHK logoutOfService:@"SHKFacebook"] 会产生不同的结果。

当我重新登录时,登录屏幕不显示。相反,屏幕上会显示以下文字:“您已经授权......按确定继续。”然后在屏幕底部显示“登录身份...”和“注销”。但据说用户已经注销了。

更糟糕的是,如果我按“确定”按钮继续,我会收到错误:“操作无法完成。(NSURLErrorDomain 错误 -999。)

我想我可能需要调整 ShareKit 才能完成这项工作,但我有其他人遇到过这种情况吗?

I am using Sharekit for Facebook sharing with the Facebook Graph API. I have tried to find the latest, most up to date code (troppoli on github seems pretty up-to-date).

Using sharekit to log out of Twitter works fine with the line: [SHK logoutOfService:@"SHKTwitter"]; but the same line for Facebook, [SHK logoutOfService:@"SHKFacebook"], yields different results.

When I go to log back in, the login screen does not show. Instead, a screen with the text: "You have already authorized ... Press okay to continue." Then at the bottom of the screen, "Logged in as ..." and "Log out" . But the user is supposedly already logged out.

Even worse, if I press the "Okay" button to continue on, I get the error: "The operation couldn't be completed. (NSURLErrorDomain error -999.)

I think I may need to tweak ShareKit to make this work but I hate to do that. Has anyone else come across this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你是暖光i 2024-12-16 14:33:45

您需要确保在 info.plist 中正确设置 URL 方案。在您的 info.plist 中,确保您为 Facebook 设置了 CFBundleURLTypes:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string></string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb{app_id}</string>
        </array>
    </dict>
</array>

将 {app_id} 替换为您的 Facebook 应用程序 ID。

您还需要在应用程序委托中添加一个处理程序,以便在用户通过 Mobile Safari 进行身份验证后响应回调:

-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
    return [SHKFacebook handleOpenURL:url];
}

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication 
         annotation:(id)annotation{
    return [SHKFacebook handleOpenURL:url];
}

这些更改为我解决了这个问题。

You need to make sure you set up the URL scheme in your info.plist properly. In your info.plist, make sure you have your CFBundleURLTypes set up for Facebook:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string></string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb{app_id}</string>
        </array>
    </dict>
</array>

Replace {app_id} with your facebook app id.

You also need to add a handler in your app delegate to respond to the callback after the user has authenticated through Mobile Safari:

-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
    return [SHKFacebook handleOpenURL:url];
}

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication 
         annotation:(id)annotation{
    return [SHKFacebook handleOpenURL:url];
}

These changes fixed this issue for me.

静若繁花 2024-12-16 14:33:45

我很确定这与新的 Facebook 单点登录 (SSO) 有关。如果用户安装了 Facebook 版本 3.2.3 或更高版本,或者如果设备(或模拟器)上有 Safari,则授权现在在应用程序外部进行。当我找到它时会发布更多内容。

编辑:除了 NSURL 错误之外,这似乎是新 Facebook SSO 的预期行为。用户在“注销”您的应用程序后应该保持伪登录/注销状态,以防他们登录到另一个应用程序等 - 现在都已连接。要真正注销 Facebook(也就是说,以其他人的身份登录等),用户似乎需要单击授权 Web 视图上的注销链接,该链接会在您的应用程序中“注销”Facebook 时显示。我可能是错的,但我对此很确定。

除了上述之外,我确实找到了一种摆脱 NSURL 错误的方法,这使得事情变得更好,更令人愉快。请参阅如何修复 NSURLErrorDomain iPhone 中的错误 -999

有关新 Facebook SSO 的更多信息:

摘自 Facebook iOS 教程 (特别参见最后一段):

第 3 步:实施单点登录 (SSO)

iOS SDK 最引人注目的功能之一是单点登录
(单点登录)。 SSO 允许用户使用 Facebook 登录您的应用
身份。如果他们已经登录 Facebook iOS 应用程序
他们甚至不需要在他们的设备上输入用户名和密码。
此外,因为他们通过 Facebook 登录您的应用程序
身份,您可以获得用户的许可来访问他们的
个人资料信息和社交图谱。

SSO 的主要工作原理是将用户重定向到其上的 Facebook 应用
设备。由于用户已经登录 Facebook,因此他们不会
需要输入用户名和密码来识别自己的身份。他们
将看到身份验证对话框,其中包含您的应用程序请求的权限
如果他们允许,那么他们将被重定向到您的应用程序
适当的access_token。

开发人员应该意识到 Facebook SSO 的行为会略有不同
根据用户设备上安装的内容而有所不同。这是
在某些配置下会发生什么:

如果应用程序运行在支持多任务处理的 iOS 版本中,
如果设备有 Facebook 应用程序版本 3.2.3 或更高版本
安装后,SDK 会尝试打开授权对话框
Facebook 应用程序。用户授予或拒绝授权后,
Facebook 应用程序重定向回调用应用程序,并传递
授权令牌、过期时间以及 Facebook 的任何其他参数
OAuth 服务器可能会返回。

如果设备运行的 iOS 版本支持
多任务处理,但它没有版本 3.2.3 的 Facebook 应用程序或
安装得更大,SDK会打开授权对话框
野生动物园。用户授予或撤销授权后,Safari
重定向回调用应用程序。类似于基于Facebook的应用程序
授权,这允许多个应用程序共享同一个 Facebook
用户通过 Safari cookie 获取 access_token。

如果应用程序运行的 iOS 版本不支持
多任务处理时,SDK 使用旧的弹出内联机制
UIWebView,提示用户登录并授予访问权限。这
FBSessionDelegate 是您的应用程序应该使用的回调接口
实现:当应用程序运行时,将调用委托的方法
成功登录或注销。阅读 iOS SDK 文档
有关该代表的更多详细信息。

...

当用户想要停止使用 Facebook 与您的应用集成时,
您可以调用注销方法来清除应用程序状态并进行
服务器请求使当前的access_token失效。

[facebook 注销:self];您可以实现 fbDidLogout 方法
FBSessionDelegate 协议来处理您的任何注销后操作
希望采纳。

请注意,注销不会撤销您的应用程序的权限,
但只会清除您应用程序的 access_token。如果用户
之前已注销您的应用程序返回,他们只会看到
他们正在登录您的应用程序的通知,而不是通知
授予权限。修改或撤销应用程序
权限,用户可以访问“应用程序、游戏和
Facebook 隐私设置仪表板的“网站”选项卡。您可以
还可以使用 Graph API 以编程方式撤销应用程序的权限
打电话。

希望这有帮助,如果您发现任何不同之处,请告诉我。

I'm pretty sure this has something to do with the new Facebook Single-Sign-On (SSO). If the user has Facebook version 3.2.3 or greater installed, or if Safari is on the device (or simulator), authorization now takes place OUTSIDE of the app. Will post more as I find it.

EDIT: Apart from the NSURL error, it seems that this is the expected behavior with the new Facebook SSO. Users are supposed to remain in a pseudo-logged in/logged out state after 'logging out' of your app, in case they are logged into another app, etc. - it's all connected now. To really log out of facebook (to say, log in as someone else, etc.) it seems that the user needs to click the logout link on the authorization webview that shows when they are "logged out" of facebook in your app. I could be wrong but I'm pretty sure about this.

Apart from the above, I did find a way to get rid of the NSURL error and this makes things a lot better, and much more palatable. See How Do I Fix NSURLErrorDomain Error -999 in iPhone.

For more on the new Facebook SSO:

Excerpt from Facebook iOS Tutorial (see especially last paragraph):

Step 3: Implementing Single Sign-On (SSO)

One of the most compelling features of the iOS SDK is Single-Sign-On
(SSO). SSO lets users sign into your app using their Facebook
identity. If they are already signed into the Facebook iOS app on
their device they do not have to even type a username and password.
Further, because they are signing to your app with their Facebook
identity, you can get permission from the user to access to their
profile information and social graph.

SSO primarily works by redirecting the user to the Facebook app on her
device. Since the user is already logged into Facebook, they will not
need to enter their username and password to identify themselves. They
will see the auth dialog with the permissions that your app has asked
for and if they allow then they will be redirected to your app with
the appropriate access_token.

Developers should be aware that Facebook SSO will behave slightly
different depending on what is installed on the user's device. This is
what happens in certain configurations:

If the app is running in a version of iOS that supports multitasking,
and if the device has the Facebook app of version 3.2.3 or greater
installed, the SDK attempts to open the authorization dialog within
the Facebook app. After the user grants or declines the authorization,
the Facebook app redirects back to the calling app, passing the
authorization token, expiration, and any other parameters the Facebook
OAuth server may return.

If the device is running in a version of iOS that supports
multitasking, but it doesn't have the Facebook app of version 3.2.3 or
greater installed, the SDK will open the authorization dialog in
Safari. After the user grants or revokes the authorization, Safari
redirects back to the calling app. Similar to the Facebook app based
authorization, this allows multiple apps to share the same Facebook
user access_token through the Safari cookie.

If the app is running a version of iOS that does not support
multitasking, the SDK uses the old mechanism of popping up an inline
UIWebView, prompting the user to log in and grant access. The
FBSessionDelegate is a callback interface that your app should
implement: The delegate's methods will be invoked when the app
successful logs in or logs out. Read the iOS SDK documentation for
more details on this delegate.

...

When the user wants to stop using Facebook integration with your app,
you can call the logout method to clear the app state and make a
server request to invalidate the current access_token.

[facebook logout:self]; You may implement the fbDidLogout method of
the FBSessionDelegate protocol to handle any post-logout actions you
wish to take.

Note that logging out will not revoke your application's permissions,
but will simply clear your application's access_token. If a user that
has previously logged out of your app returns, they will simply see a
notification that they are logging into your app, not a notification
to grant permissions. To modify or revoke an application's
permissions, the user can visit the "Applications, Games, and
Websites" tab of their Facebook privacy settings dashboard. You can
also revoke an app's permissions programmatically using a Graph API
call.

Hope this helps, let me know if you find anything different.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文