简体   繁体   English

Facebook iOS SDK:无需显示对话框即可刷新过期的访问令牌

[英]Facebook iOS SDK: refreshing an expired access token without presenting a dialog

I'm using the Facebook iOS SDK . 我正在使用Facebook iOS SDK In my code I have authorized my app with the default permissions, so my session is valid until the expiration date is reached. 在我的代码中,我已使用默认权限授权了我的应用程序,因此我的会话在直到到期日期之前一直有效。 However, after the expiration date is reached, I attempt to reauthorize in order to "refresh my OAuth token", as asked before . 但是,在到期日期之后,我尝试重新授权以“刷新我的OAuth令牌”,如之前所述

However, when I attempt to reauthorize, it displays a dialog saying I have already authorized my app, even though I expect it to just update my OAuth token without a dialog. 但是,当我尝试重新授权时,即使我希望它仅更新我的OAuth令牌而不显示对话框,也会显示一个对话框,表明我已经授权了我的应用程序。 According to facebook, this is possible : 根据facebook, 这是可能的

When you redirect the user to the auth dialog, the user is not prompted for permissions if the user has already authorized your application. 当您将用户重定向到auth对话框时,如果用户已经授权了您的应用程序,则不会提示用户权限。 Facebook will return you a valid access token without any user facing dialog . Facebook将向您返回有效的访问令牌,而无需面对任何用户对话

However, I do get a dialog and I'd like to know how I can refresh the access token without getting the dialog. 但是,我确实有一个对话框,我想知道如何在没有对话框的情况下刷新访问令牌。

A recent commit in the Facebook iOS SDK project included an "extend access token" method for extending an expired token. Facebook iOS SDK项目中的最近提交包含用于扩展过期令牌的“扩展访问令牌”方法。

More information about this and the deprecation of "offline_access" is in Facebook Developer's blog post . 有关此问题和弃用“ offline_access”的更多信息,请参阅Facebook Developer的博客文章

A possible work around is to request offline_access as a permission. 可能的解决方法是请求offline_access作为权限。 Then the access token only expires when: 然后,访问令牌仅在以下情况下过期:

The user logs out of facebook Changes their password Revokes permissions for your app via the facebook website 用户注销Facebook更改密码通过Facebook网站撤消您的应用程序的权限

If anyone has a better answer id like to know too. 如果有人有更好的答案ID,我也想知道。 Requesting offline access for my app could look a bit suspicious (even though the only reason I need it is for non-expiring access token, I wont actually be accessing a users account when their not using my app). 请求对我的应用程序进行脱机访问可能看起来有点可疑(即使我需要它的唯一原因是未过期的访问令牌,当他们不使用我的应用程序时,我实际上不会访问用户帐户)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM