简体   繁体   English

如何使用Python库获取Facebook访问令牌?

[英]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? 注意:我真的不明白,为什么我们可以使用urllibregex提取信息,为什么使用库并且无法提取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.

相关问题 Facebook:如何使用python获取/更新用户访问令牌? - Facebook: How to get/update user access token using python? 如何使用python获取Facebook OAuth令牌? - How to get facebook oauth token using python? 使用 Python 获取 Facebook 用户访问令牌和使用 Firefox 的本地主机 - Get Facebook user access token using Python and local host with Firefox 如何使用Facebook Python SDK从访问令牌中获取用户的电子邮件 - How to get a user's email from an access token using the Facebook Python SDK 使用Python请求库获取Google的访问令牌 - Get access token for google by using Python requests library 如何在python中从Facebook的oauth重定向获取访问令牌? - How to get the access token from facebook's oauth redirect in python? 如何解决Facebook在Python中获取访问令牌错误? - how to solve facebook get access token error in python? 如何使用facebook python sdk在facebook中扩展页面的access_token - How to extend the access_token of a page in facebook using facebook python sdk 如何在python中获取访问令牌 - how to get access token in python 在 Python 中从 Paypal 获取访问令牌 - 使用 urllib2 或 requests 库 - Get access token from Paypal in Python - Using urllib2 or requests library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM