views:

95

answers:

2

Hi,

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 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.

A: 

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.

Andrew67
A: 

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.

Anurag
Thanx. One more thing If i want basic info about user's friends like name, id and photourl. Is it possible to retrieve using FB's Javascript API??
Nick
Yes, you can access that information as far as I know. Read up more about it at http://developers.facebook.com/docs/reference/javascript/#core-methods. You can also issue FQL queries from this SDK.
Anurag