facebook.GraphAPIError:必须使用活动的访问令牌来查询有关当前用户的信息 [英] facebook.GraphAPIError: An active access token must be used to query information about the current user

查看:144
本文介绍了facebook.GraphAPIError:必须使用活动的访问令牌来查询有关当前用户的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在收到此错误,尝试打印我的朋友列表一段时间。我相当肯定我提供了一个令牌。有什么想法吗?

I have been getting this error trying to print my friends list for awhile. I am fairly certain I am providing a token. Any idea's on this?

import facebook
import urllib
import urllib2
import json
import urlparse
import subprocess
import warnings
import urllib2
import json
#https://developers.facebook.com/tools/access_token/
# Parameters of your app and the id of the profile you want to mess with.
FACEBOOK_APP_ID     = '{app_id}'
FACEBOOK_APP_SECRET = '{app_secret}'
FACEBOOK_PROFILE_ID = 'my-id-number-here'
# Trying to get an access token. Very awkward.
oauth_args = dict(client_id     = FACEBOOK_APP_ID,
                  client_secret = FACEBOOK_APP_SECRET,
                  grant_type    = 'client_credentials')
oauth_curl_cmd = ['curl',
                  'https://graph.facebook.com/oauth/access_token?' +   urllib.urlencode(oauth_args)]
oauth_response = subprocess.Popen(oauth_curl_cmd,
                                  stdout = subprocess.PIPE,
                                  stderr = subprocess.PIPE).communicate()[0]
try:
    oauth_access_token = urlparse.parse_qs(str(oauth_response))['access_token'][0]
except KeyError:
    print('Unable to grab an access token!')
    exit()
facebook_graph = facebook.GraphAPI(oauth_access_token)
# Print friends list.
profile = facebook_graph.get_object("me")
friends = facebook_graph.get_connections("me", "friends")
friend_list = [friend['name'] for friend in friends['data']]
print friend_list


推荐答案

您收到此错误是因为您使用的访问令牌不是用户令牌。

You are getting this error cause you are using an access token not a user token.

可以使用Facebook开发人员生成用户令牌

The user token can be generated by using facebook developers

https://developers.facebook.com/tools/explorer/145634995501895 /

只需点击获取令牌>获取用户访问令牌
这对我来说是个窍门

Just click Get Token > Get User Access Token This does the trick for me

这篇关于facebook.GraphAPIError:必须使用活动的访问令牌来查询有关当前用户的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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