views:

100

answers:

2

Hi,

I am using facebook graph. I am able to retrieve the access_token. Now I want to get info using

https://graph.facebook.com/XXXXXXXXX/?access_token=111978178853984|2.1lD7XrS1n7C3UgudmiSpQg__.3600.1279976400-10000XXXXXXXXX|9vJZuRDvlzLhFfGkqGkg92KmDSE.

I already multiple ways to retrieve json output.

1) jquery.getJSON method - Falied due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol

2) tried file_get_contents method - Falied again - Unfortunately I am using shared server, file_get_contents is not allowed.

3) tried httpSocket method - failed - I get output as null.

I am running out ideas to get it work. I am not familiar with cURL.

I appreciate any help.

Thanks.

+1  A: 

You can use jQuery.getJSON()/$.getJSON() but you need to make a slight addition to the URL by adding &callback=? on there, like this:

https://graph.facebook.com/XXXXXXXXX/?access_token=111978178853984|2.1lD7XrS1n7C3UgudmiSpQg__.3600.1279976400-10000XXXXXXXXX|9vJZuRDvlzLhFfGkqGkg92KmDSE&callback=?

Then just use that url:

$.getJSON('https://graph.facebook.com/XXXXXXXXX/?access_token=111978178853984|2.1lD7XrS1n7C3UgudmiSpQg__.3600.1279976400-10000XXXXXXXXX|9vJZuRDvlzLhFfGkqGkg92KmDSE&callback=?', function(data) {
  //use data, it's a json object
});

This will request the content in a different way, using JSONP which will get around the same-origin policy (and facebook supports this).

Nick Craver
A: 

Try using either the official Facebook PHP SDK, or the JavaScript SDK.

Martin Bean