javascript - FB.api Response Is Undefined - Stack Overflow

I'm developing a website which integrates with a facebook account to display the notes from the fa

I'm developing a website which integrates with a facebook account to display the notes from the facebook account on the website. However after calling the FB.api method the response I receive is undefined and I am unable to access the data in 'response.data'.

Test

<body>
    <div id="fb-root"></div>
    <script src=".js"></script>
    <script>

    window.fbAsyncInit =    function() 
                            {

                                FB.init({appId: '12345678', status: true, cookie: true, xfbml: true});

                                FB.api  (
                                            '/pagename/notes',  
                                            function(response) 
                                            {

                                                alert(response.data.length);

                                            }

                                        );

                            };

    </script>

</body>

Has anyone any idea where I'm going wrong? Any help would be much appreciated.

Thanks.

I'm developing a website which integrates with a facebook account to display the notes from the facebook account on the website. However after calling the FB.api method the response I receive is undefined and I am unable to access the data in 'response.data'.

Test

<body>
    <div id="fb-root"></div>
    <script src="http://connect.facebook/en_US/all.js"></script>
    <script>

    window.fbAsyncInit =    function() 
                            {

                                FB.init({appId: '12345678', status: true, cookie: true, xfbml: true});

                                FB.api  (
                                            '/pagename/notes',  
                                            function(response) 
                                            {

                                                alert(response.data.length);

                                            }

                                        );

                            };

    </script>

</body>

Has anyone any idea where I'm going wrong? Any help would be much appreciated.

Thanks.

Share Improve this question edited Oct 21, 2014 at 12:11 slickboy asked Jun 5, 2012 at 12:44 slickboyslickboy 4612 gold badges8 silver badges24 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

If you use console.log on the response object, you'll realize that it includes an "error" property and that response.error.message is "An access token is required to request this resource."

You can check if your response includes an error by using the following:

function (response) {
    if (response.hasOwnProperty("error")) {
        alert("Error: " + response.error.message);
    } else {
        //Success!
    }
}

For the error, a similiar question can be found here: "An access token is required to request this resource" while accessing an album / photo with Facebook php sdk

Reading notes requires read_stream permission – your code doesn’t look like you got it first. https://developers.facebook./docs/authentication/permissions/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745662324a4638911.html

相关推荐

  • javascript - FB.api Response Is Undefined - Stack Overflow

    I'm developing a website which integrates with a facebook account to display the notes from the fa

    9小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信