如何在python中扩展facebook访问令牌 [英] How to extend facebook access token in python

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

问题描述

我使用的是Python的facebook-sdk客户端库。
我目前拥有从 https://developers.facebook.com获取的短暂访问令牌/ tools / accesstoken / ,我将代码从站点复制到我的验证代码。

I am using the Python facebook-sdk client library. I currently have a short-lived access token obtained from https://developers.facebook.com/tools/accesstoken/ that I copy the code from the site into my code for authentication.

       graph = facebook.GraphAPI(access_token)

然而,这个令牌在60分钟后过期。我希望将其扩展到60天的生存令牌,以便每次到期时都不需要手动复制。我可以找到许多关于如何以不同的格式做的答案,但不是python(或至少不是简单的没有登录页面等)。

This token however expires after 60-mins. I am looking to extend this to a 60 day-long lived token so that don't need to manually copy in new every time it expires. I can find numerous answers on how to do this in different formats, however not python (or at least not simply without log in page etc.).

[作为参考,我将使用的代码仅供我使用,因此我不打算创建一个登录页面。我只是想能够扩展我已经拥有的令牌。

[for reference, the code I will be using is only intended for my use, and as such, I am not looking to create a log in page. I just want to be able to extend the token I already have].

推荐答案

不知道这是否在python的FB API中可用当问题最初被问到时,但是更为方便延长访问令牌的到期时间将是:

Not sure if this was available in python's FB API when the question was originally asked, but a neater approach to extend the expiry of the access token would be:

graph = facebook.GraphAPI(user_short_lived_token_from_client)
app_id = 'app_id' # Obtained from https://developers.facebook.com/
app_secret = 'app_secret' # Obtained from https://developers.facebook.com/

# Extend the expiration time of a valid OAuth access token.
extended_token = graph.extend_access_token(app_id, app_secret)
print extended_token #verify that it expires in 60 days

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

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