Facebook 脚本没有错误,但仍未显示结果

发布于 2024-12-19 20:56:50 字数 694 浏览 3 评论 0原文

我对 Facebook Javascript API 非常陌生。我需要帮助才能根据我创建的好友列表获取好友列表。比如“毕业生、学校、朋友、共事者”(所有这些都是自己创建的)。

这是到目前为止我所做的。我已成功登录并为该会话分配了正确的 access_token。之后我运行这个。

    FB.login(function(response) {
        if( response.session ){
            *FB.api('friendlist', '/me/friendlists', function(){
                **alert('got the friendlist');
            });
        }else{
            alert('User not logged in.');
        }
    },{scope: 'email,read_friendlists'});

在此代码上

* 运行正常,没有任何异常?

** 此警报从不调用?

只是想问几件事。

有没有正确的方法来查看异常。如果我们也有异常回调?

以及如何使用 JS API 从 FB 获取 FriendList 列表。

谢谢,

塔尔哈·艾哈迈德·汗

I am very new to FaceBook Javascript API. I need help to get the fiends list according to the Friend List i have created. Like 'Grads, School, Friends, Worked with' (All of these are self created).

This is so far I have done right now. I am successfully logged in and have proper access_token allocated to this session. After that I run this.

    FB.login(function(response) {
        if( response.session ){
            *FB.api('friendlist', '/me/friendlists', function(){
                **alert('got the friendlist');
            });
        }else{
            alert('User not logged in.');
        }
    },{scope: 'email,read_friendlists'});

On this code

* this runs OK without any exceptions?

** this alert never invokes?

Just want to ask few things.

Is there a proper way to see the exception. If we have a callback for exception as well?

and How to get the List of FriendList from FB using JS API.

Thanks,

Talha Ahmed khan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

马蹄踏│碎落叶 2024-12-26 20:56:51

我已经尝试过了,它似乎有效。

 <div id="listsDiv"></div>

 <script>
 var listsDiv = document.getElementById('listsDiv');
 FB.getLoginStatus(function(response) {
 if (response.status != 'connected') {
 listsDiv.innerHTML = '<em>You are not connected</em>';
 return;
 }


 });

 var perms = function(){
 FB.api('/me/friendlists', function(result) {

 var markup = '';
 var lists = result.data;
 for(var i in lists){
   markup += lists[i].name +'<br />';
 }
 listsDiv .innerHTML = markup;
 });
 }
 FB.login(perms, { scope: 'read_friendlists' });
 </script>

您可以在

https:// Developers.facebook.com/tools/console/

I've tried this and it seems to work

 <div id="listsDiv"></div>

 <script>
 var listsDiv = document.getElementById('listsDiv');
 FB.getLoginStatus(function(response) {
 if (response.status != 'connected') {
 listsDiv.innerHTML = '<em>You are not connected</em>';
 return;
 }


 });

 var perms = function(){
 FB.api('/me/friendlists', function(result) {

 var markup = '';
 var lists = result.data;
 for(var i in lists){
   markup += lists[i].name +'<br />';
 }
 listsDiv .innerHTML = markup;
 });
 }
 FB.login(perms, { scope: 'read_friendlists' });
 </script>

You can test a lot of this stuff out at

https://developers.facebook.com/tools/console/

时光沙漏 2024-12-26 20:56:51

根据文档,FB.api 返回一个响应对象,您可以使用它来调试错误。

https://developers.facebook.com/docs/reference/javascript/FB。 api/

修改后的代码:

FB.login(function(response) {
        if( response.session ){
            FB.api('friendlist', '/me/friendlists', function(response){
                alert(response.error);
            });
        }else{
            alert('User not logged in.');
        }
    },{scope: 'email,read_friendlists'});

如果您想查看“响应”上有哪些属性,您可以使用 firebug 或 chrome 的调试控制台之类的东西,而不是:

alert(reponse.error);

您可以使用

console.log(response);

According to the documentation, FB.api returns a response object which you can use to debug the error.

https://developers.facebook.com/docs/reference/javascript/FB.api/

revised code:

FB.login(function(response) {
        if( response.session ){
            FB.api('friendlist', '/me/friendlists', function(response){
                alert(response.error);
            });
        }else{
            alert('User not logged in.');
        }
    },{scope: 'email,read_friendlists'});

if you want to see what properties are on 'response', you could use something like firebug or chrome's debug console and instead of:

alert(reponse.error);

you could use

console.log(response);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文