线程化Facebook API访问令牌

2024-09-27 07:29:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我不熟悉穿线。事实上,我以前从未学过。在

我正在尝试使用线程从Facebook检索访问令牌,以便我的访问令牌能够自动扩展,而不必每一小时手动检索一次。在

我要做的是: enter image description here

所以我在Stackoverflow中看到了一些与线程相关的代码,并尝试了一下。最终,它是可行的,但我如何只收集Facebook访问令牌?谁能帮帮我吗?在

import Queue
import threading
import urllib2

# called by each thread
def get_url(q, url):
q.put(urllib2.urlopen(url).read())

theurls = ["My facebook developer gpaph api explorer URL"]

q = Queue.Queue()

for u in theurls:
t = threading.Thread(target=get_url, args = (q,u))
t.daemon = True
t.start()

s = q.get()

print s

Tags: 代码importurlgetfacebookqueue手动urllib2
1条回答
网友
1楼 · 发布于 2024-09-27 07:29:45

有两件事我不清楚

  1. 你为什么不把活命牌换成长寿

https://developers.facebook.com/docs/facebook-login/access-tokens#extending中所述,您可以将短期代币兑换为有效期为60天的长期代币。短命的只在2小时内有效。在

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

根据您想使用访问令牌做什么,您还可以使用应用程序或(永久)页面访问令牌。它们都不会过期,所以你的问题会得到解决。在

  1. 这整件事和穿线有什么关系。在

相关问题 更多 >

    热门问题