[英]How to get Facebook access token using Python library?
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! 我发现这个库似乎是正式的,然后发现了这个 ,但每次我找到答案时,其中一半是Facebook API文档的链接,它谈论Javascript或PHP以及如何从链接中提取它!
How do i make it on simple python script? 我如何在简单的python脚本上创建它?
NB: what i realy dont understand, why using a library and cant extract token
if we can use urllib
and regex
to extract informations? 注意:我真的不明白,为什么我们可以使用urllib
和regex
提取信息,为什么使用库并且无法提取token
?
Not sure if this helps anyone, but I was able to get an oauth_access_token by following this code. 不确定这是否有助于任何人,但我能够通过遵循此代码获得oauth_access_token。
from facepy import utils
app_id = 134134134134 # must be integer
app_secret = "XXXXXXXXXXXXXXXXXX"
oath_access_token = utils.get_application_access_token(app_id, app_secret)
Hope this helps. 希望这可以帮助。
Javascript and PHP can be used as web development languages. Javascript和PHP可以用作Web开发语言。 You need a web front end for the user to grant permission so that you can obtain the access token. 您需要一个Web前端,以便用户授予权限,以便您可以获取访问令牌。
Rephrased: You cannot obtain the access token programmatically, there must be manual user interaction 重新说明: 您无法以编程方式获取访问令牌,必须有手动用户交互
In Python it will involve setting up a web server, for example a script to update feed using facepy 在Python中,它将涉及设置Web服务器,例如使用facepy更新feed的脚本
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')
here is a Gist i tried to make using Tornado
since the answer uses web.py
这是一个我试图使用Tornado
的Gist,因为答案使用web.py
https://gist.github.com/abdelouahabb/5647185 https://gist.github.com/abdelouahabb/5647185
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.