开发者

How to facebook user's information

I am usin开发者_运维知识库g 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.


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


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜