facebook API 中的刷新令牌和访问令牌 [英] Refresh token and Access token in facebook API

查看:26
本文介绍了facebook API 中的刷新令牌和访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们在 google api 上执行 oauth2 时,我们会得到一个访问令牌和一个刷新令牌.假设我正在编写一个服务并且我想定期轮询更改,我可以在每次当前访问令牌失效时使用刷新令牌来获取新的访问令牌.这称为离线访问.

When we do oauth2 on google api, we get an access token and a refresh token. Suppose I'm writing a service and I want to periodically poll for changes I can just use refresh token to get fresh access tokens every time the current access token gets invalidated. This is called offline access.

有什么办法可以在 facebook 中做同样的事情吗?有没有类似google api的离线访问版本.

Is there any way to do the same in facebook? Is there an offline access version similar to that of google api.

谢谢.

推荐答案

对于离线访问,您需要在短期访问令牌过期之前将其交换为新的访问令牌.Facebook 有单一类型的访问令牌(无刷新令牌).一个即将过期的访问令牌应该会为您获取一个新的访问令牌.

For offline access, you need to exchange your short-lived access token for a new access token, before it expires. Facebook has a single type of access token (no refresh tokens). A about-to-expire access token should fetch you a new access token.

使用图形 API 端点手动扩展令牌 ::

To manually extend the tokens using a Graph API endpoint ::

GET /oauth/access_token?  
    grant_type=fb_exchange_token&           
    client_id={app-id}&
    client_secret={app-secret}&
    fb_exchange_token={short-lived-token}

此处 ::

应用程序无法将过期的短期令牌交换为长寿命令牌.以上流程仅适用于短期令牌仍然有效.一旦过期,您的应用程序必须向用户发送再次通过登录流程.

Apps are unable to exchange an expired short-lived token for a long-lived token. The flow above only works with short-lived tokens that are still valid. Once they expire, your app must send the user through the login flow again.

请阅读我提到的文档链接的 Expiration and Extending Tokens 部分以进一步说明.

Do read the Expiration and Extending Tokens portion of the documentation link that I have mentioned for further clarification.

这篇关于facebook API 中的刷新令牌和访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆