Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python facebook.GraphAPIError:必须使用活动访问令牌来查询有关当前用户的信息_Python_Facebook - Fatal编程技术网

Python facebook.GraphAPIError:必须使用活动访问令牌来查询有关当前用户的信息

Python facebook.GraphAPIError:必须使用活动访问令牌来查询有关当前用户的信息,python,facebook,Python,Facebook,一段时间以来,我一直在打印朋友列表时出错。我相当肯定我在提供代币。有什么想法吗 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 ap

一段时间以来,我一直在打印朋友列表时出错。我相当肯定我在提供代币。有什么想法吗

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

您的短期访问令牌可能已过期。你可以通过


并检查访问令牌的有效性。

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

用户令牌可以使用facebook开发者生成

只需单击获取令牌>获取用户访问令牌 这对我有好处