Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.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
FQL Javascript访问令牌_Javascript_Facebook_Facebook Graph Api_Facebook Fql - Fatal编程技术网

FQL Javascript访问令牌

FQL Javascript访问令牌,javascript,facebook,facebook-graph-api,facebook-fql,Javascript,Facebook,Facebook Graph Api,Facebook Fql,我对以任何形式使用FQL都很陌生,如果这是一个简单的问题,很抱歉,但我似乎无法回避它 我有以下代码试图获取朋友列表: var query = FB.Data.query('SELECT '+response.id+', '+response.name+' FROM friendlist from user where uid=' + response.id); 但我不断得到的回应是 “必须使用活动访问令牌来查询有关当前用户的信息。” 当我从/me查询中提取响应对象时,我看到了所有信息,如位置、

我对以任何形式使用FQL都很陌生,如果这是一个简单的问题,很抱歉,但我似乎无法回避它

我有以下代码试图获取朋友列表:

var query = FB.Data.query('SELECT '+response.id+', '+response.name+' FROM friendlist from user where uid=' + response.id);
但我不断得到的回应是

“必须使用活动访问令牌来查询有关当前用户的信息。”

当我从/me查询中提取响应对象时,我看到了所有信息,如位置、名称、工作等,但没有看到任何访问令牌

代码是这样开始的:

window.fbAsyncInit = function() {
            FB.init({appId: '12...0', status: true, cookie: true, xfbml: true});

            /* All the events registered */
            FB.Event.subscribe('auth.login', function(response) {
                // do something with response
                login();
            });
            FB.Event.subscribe('auth.logout', function(response) {
                // do something with response
                logout();
            });

            FB.getLoginStatus(function(response) {
                if (response.session) {
                    // logged in and connected user, someone you know
                    login();
                }
            });
var query = FB.Data.query('SELECT '+response.id+', '+response.name+' FROM friendlist from user where uid=' + response.id + '&access_token='+response.session.access_token);
如何获取访问令牌并随FQL查询一起提供


感谢您提前提出的建议

用户成功登录后,facebook会提供您必须使用的访问令牌,以便对Graph API执行所有类型的请求(包括FQL查询)

如果您使用的是firebug,请在用户登录后执行
控制台.log(响应)
以查看您收到的对象

 FB.Event.subscribe('auth.login', function(response) {
     console.log(response);   
     // do something with response
     login();
 });
它应该包含3个属性:
perms
session
status
perms
包含一个由用户授予权限的列表,
状态是当前用户的状态。对您来说重要的是
会话
属性。这一个它也是一个对象,其中有一个
access\u token
属性(字符串),您可以使用该属性对API进行请求

因此,您的查询可能如下所示:

window.fbAsyncInit = function() {
            FB.init({appId: '12...0', status: true, cookie: true, xfbml: true});

            /* All the events registered */
            FB.Event.subscribe('auth.login', function(response) {
                // do something with response
                login();
            });
            FB.Event.subscribe('auth.logout', function(response) {
                // do something with response
                logout();
            });

            FB.getLoginStatus(function(response) {
                if (response.session) {
                    // logged in and connected user, someone you know
                    login();
                }
            });
var query = FB.Data.query('SELECT '+response.id+', '+response.name+' FROM friendlist from user where uid=' + response.id + '&access_token='+response.session.access_token);
如果希望以更好的方式获取会话,请使用返回当前会话的
FB.getSession
。更多信息


祝你好运

用户成功登录后,facebook会提供您必须使用的访问令牌,以便对Graph API执行所有类型的请求(包括FQL查询)

如果您使用的是firebug,请在用户登录后执行
控制台.log(响应)
以查看您收到的对象

 FB.Event.subscribe('auth.login', function(response) {
     console.log(response);   
     // do something with response
     login();
 });
它应该包含3个属性:
perms
session
status
perms
包含一个由用户授予权限的列表,
状态是当前用户的状态。对您来说重要的是
会话
属性。这一个它也是一个对象,其中有一个
access\u token
属性(字符串),您可以使用该属性对API进行请求

因此,您的查询可能如下所示:

window.fbAsyncInit = function() {
            FB.init({appId: '12...0', status: true, cookie: true, xfbml: true});

            /* All the events registered */
            FB.Event.subscribe('auth.login', function(response) {
                // do something with response
                login();
            });
            FB.Event.subscribe('auth.logout', function(response) {
                // do something with response
                logout();
            });

            FB.getLoginStatus(function(response) {
                if (response.session) {
                    // logged in and connected user, someone you know
                    login();
                }
            });
var query = FB.Data.query('SELECT '+response.id+', '+response.name+' FROM friendlist from user where uid=' + response.id + '&access_token='+response.session.access_token);
如果希望以更好的方式获取会话,请使用返回当前会话的
FB.getSession
。更多信息

祝你好运