简体   繁体   English

使用JavaScript的新offline_access令牌实现Facebook应用

[英]New offline_access token implementation Facebook App with javascript

I have been working with Facebook OAuth 2.0 using JavaScript SDK. 我一直在使用JavaScript SDK使用Facebook OAuth 2.0。 I saw that Facebook has recently changed the "infinite" expiration time access token feature and now one has gets an Access token for offline access which is valid only for 60 days maximum. 我看到Facebook最近更改了“无限”到期时间访问令牌功能,现在一个人已经获得了用于离线访问的访问令牌,该令牌最多只能使用60天。

I tried the following code: 我尝试了以下代码:

FB.init({appId: 'XXXXXXXXXXXX', oauth: true , secret: 'XXXXXXXXXXXXXXXXXXXXXXXXX' });
// the real values of appId and secret are not displayed for obv reasons
FB.login(function(response) 
{
  if(response.authResponse){

}
else{
 console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'read_stream,publish_stream,offline_access'});

In my response: response.authResponse, I receive an access token and a value : expiresIn which is more or less around 6000. I don't understand what this value signifies. 在我的响应中:response.authResponse,我收到一个访问令牌和一个值:expiresIn,它大约在6000左右。我不明白该值表示什么。 if I divide it by 3600, I would say it gives me around 2 hours of validity which means this is not an access token with infinite expiration time. 如果我将其除以3600,我会说它使我大约有2个小时的有效期,这意味着这不是具有无限到期时间的访问令牌。 Is there a way I can request for an access token with longer validity? 有没有一种方法可以请求具有更长有效性的访问令牌? Kindly let me know what I am doing wrong. 请让我知道我在做什么错。

I think this policy change is confusing right now because they are changing this today. 我认为此政策更改现在令人困惑,因为他们今天正在更改此设置。
Till the new policy applies, you might need to change your app configuration as described here . 直到适用新政策,您可能需要按此处所述更改应用程序配置。
I guess you have to check your "deprecate offline_access"" setting. 我想您必须检查“不赞成使用offline_access”设置。
As long as offline_access is not given and new policy is not applied, access_token usually expires in 2 hours. 只要未提供offline_access且未应用新策略,access_token通常会在2小时后过期。

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

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