如何在Python中获取用户访问令牌 [英] How to obtain a user access token in Python

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

问题描述

我在Facebook上使用非官方的python sdk。这对于很多图形API调用很好,但是我最近的项目需要使用更多的FQL。某些表(例如通知)需要用户访问令牌而不是应用程序访问令牌。



使用

  graph.facebook.com/oauth/access_token ?client_id = YOUR_APP_ID& client_secret = YOUR_A PP_SECRET& grant_type = client_credentials 

似乎我只得到一个App令牌回来所以在调用通知表时,我将收到一个102:需要用户访问令牌来请求此资源



此项目根本不使用浏览器,并且主要用于验证通知和从另一个应用程序生成的发布。



在这种情况下,接收用户令牌的最佳方式是什么?



感谢
N

解决方案

无法直接获取用户访问令牌登录用户与您的应用程序使用facebook身份验证流程进行交互。
没有用户可以获得的唯一令牌是应用程序令牌,您已经覆盖了。



您可以手动创建用户令牌,我认为最简单的方法是使用图形浏览器工具
只需选择右上角的应用程序,然后单击获取访问令牌按钮,然后可以检查所需的权限,之后生成的令牌将显示在文本框中,复制并使用它。



这个问题是,访问令牌是一个短命的(几个小时),如果你需要更长的时间,我建议您将创建一个仅应用服务器端身份验证的画布应用程序结束一个长命令(60天),那么你可以坚持它,并在那段时间使用它。


I'm using the unofficial python sdk for Facebook. This works fine for alot of graph api calls, but my recent project requires using more FQL. Certain tables (notifications for example) require a user access token rather than an app access token.

When using

graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_A‌​PP_SECRET&grant_type=client_credentials 

it seems I only get an App token back. So when calling the notification table I'll receive a "102 : A user access token is required to request this resource"

This project does not use a browser at all, and is mainly created to validate notifications, and postings generated from another app.

Whats the best way to receive a user token in this case?

Thanks N

解决方案

You can not get a user access token without a direct interaction of a logged in user with your application using the facebook authentication flows. The only token that can be obtained without a user is the application token and you've got that covered already.

You can create a user token manually, the easiest way, I think, would be to use the Graph Explorer tool. Just select your application on the top right, then click the "Get Access Token" button, you can then check the needed permissions and after that a generated token will appear in the text box, copy that and use it.

The problem with that is that the access token is a short lived one (a few hours), if you need a longer one I suggest that you create a canvas application that will only implement the Server-Side authentication which will end with a long-lived token (60 days), then you can persist it and use it for that time.

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

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