开发者

How to retrieve facebook user info

开发者 https://www.devze.com 2023-01-08 21:01 出处:网络
I am using facebook\'s graph api to retrieve user\'s information. First I retrieved the access_token.

I am using facebook's graph api to retrieve user's information. First I retrieved the access_token.

Then, I tried using jquery.getJSON() method to retrieve user's id and name.

<div id="result"></div>

<script>$.getJSON("https://graph.facebook.com/me/?access_token=111978178853984|2.lg65A3c0atficNsFcf7Rog__.3600.1279922400-100001XXXXXXXXX|-hHNxODbE9-8tfazmO5r3ZzIeFE.",
        function(response){
            document.getElementById('result').innerHTML = response.id;
        });</script>   

I am not开发者_Python百科 getting anything. But when i plug this into address bar i am able to see the user's id and name etc.,

I appreciate any help.

Thanks.


Can you not use FB's Javascript SDK to do the same instead of doing it through jQuery?

FB.api('/me', function(response) {
    document.getElementById('result').innerHTML = response.id; 
});

which would avoid the cross-domain issue since Facebook's JS API has access to graph.facebook.com coming from the same domain, but not your script.


Remember that AJAX calls are subject to the same-origin policy.

http://api.jquery.com/jQuery.getJSON/#jsonp

You might need to create a PHP script on your same domain that fetches the graph API result.

0

精彩评论

暂无评论...
验证码 换一张
取 消