如何使用Python库获取Facebook访问令牌? [英] How to get Facebook access token using Python library?
问题描述
我发现这个图书馆似乎是官方的,那么<一个href =https://stackoverflow.com/questions/10488913/how-to-obtain-a-user-access-token-in-python>发现这个,但每次我找到一个答案它是指向 Facebook API文档的链接,该文档涉及到Javascript或PHP和如何从链接中提取!
I've found this Library it seems it is the official one, then found this, but everytime i find an answer the half of it are links to Facebook API Documentation which talks about Javascript or PHP and how to extract it from links!
我如何使用简单的python脚本?
How do i make it on simple python script?
NB :我真的不明白,为什么使用一个库并且不能提取令牌
如果我们可以使用 urllib
和 regex
提取信息?
NB: what i realy dont understand, why using a library and cant extract token
if we can use urllib
and regex
to extract informations?
推荐答案
Javascript和PHP可以用作Web开发语言。您需要一个Web前端才能授予用户权限,以便您可以获取访问令牌。
Javascript and PHP can be used as web development languages. You need a web front end for the user to grant permission so that you can obtain the access token.
重新启动:您无法以编程方式获取访问令牌,那里必须是手动用户交互
在Python中,它将涉及设置一个Web服务器,例如使用facepy更新feed的脚本
In Python it will involve setting up a web server, for example a script to update feed using facepy
import web
from facepy import GraphAPI
from urlparse import parse_qs
url = ('/', 'index')
app_id = "YOUR_APP_ID"
app_secret = "APP_SECRET"
post_login_url = "http://0.0.0.0:8080/"
user_data = web.input(code=None)
if not user_data.code:
dialog_url = ( "http://www.facebook.com/dialog/oauth?" +
"client_id=" + app_id +
"&redirect_uri=" + post_login_url +
"&scope=publish_stream" )
return "<script>top.location.href='" + dialog_url + "'</script>"
else:
graph = GraphAPI()
response = graph.get(
path='oauth/access_token',
client_id=app_id,
client_secret=app_secret,
redirect_uri=post_login_url,
code=code
)
data = parse_qs(response)
graph = GraphAPI(data['access_token'][0])
graph.post(path = 'me/feed', message = 'Your message here')
这篇关于如何使用Python库获取Facebook访问令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!