简体   繁体   English

Facebook:如何使用python获取/更新用户访问令牌?

[英]Facebook: How to get/update user access token using python?

Currently am using Graph Explorer to get a short-lived user access token and than converting it to a extended token(60 days) by a call to facepy get_extended_access_token method. 当前正在使用Graph Explorer来获取短暂的用户访问令牌,然后通过调用facepy get_extended_access_token方法将其转换为extended token(60 days)

Now. 现在。 consider the scenario where my user access token becomes invalid because of either user logging out or the token expires itself. 考虑以下情况:由于用户注销或令牌本身过期,我的用户访问令牌无效。 So, in both the cases I need to get a new user access token because get_extended_access_token requires access_token so that it can extend it. 因此,在这两种情况下,我都需要获取新的用户访问令牌,因为get_extended_access_token需要access_token以便可以对其进行扩展。

So, my question is how to retrieve this token using python? 所以,我的问题是如何使用python检索此令牌? Is there any particular url which I can send a request and it will return a new/updated token in resonse. 是否有任何我可以发送请求的特定网址,它将以共振的方式返回新的/更新的令牌。

Update : 更新

So, after following this post and making a request to 因此,在关注此帖子并向

https://graph.facebook.com/oauth/access_token?client_id=xxxx&client_secret=yyyy&grant_type=client_credentials

I got this token which I believe is an app access token 我得到了这个令牌,我相信这是一个app access token

access_token=123456789|12abcdef234 #changed from original

But what I need is an user access token through which I can read my mailbox. 但是我需要的是一个用户访问令牌,通过它可以读取我的邮箱。

If the access token has expired or been invalidated you need to go back through the Auth Dialog, ie a user must manually re-grant access to your application. 如果访问令牌已过期或已失效,则需要返回“身份验证”对话框,即用户必须手动重新授予对应用程序的访问权限。 Retrieving it programmatically defeats the whole purpose of token invalidation/expiry. 以编程方式检索它会破坏令牌无效/失效的整个目的。

Once you get this token, you can then use get_extended_access_token to get the long lived one 一旦获得此令牌,就可以使用get_extended_access_token获得寿命长的令牌

App tokens can be used to publish a post on the user's behalf. 应用令牌可用于代表用户发布帖子。

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

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