Ivan
Ivan

Reputation: 714

Get Facebook ID with Opengraph using JQuery

I tried to grab my Facebook ID using open graph API. It is working if i use browser and browse to:
https://graph.facebook.com/IvanKristiantoBlog

But i want to grab it using JQuery, here is my sample code:
http://jsbin.com/ejogu3/2/edit
But when i debug using Firebug, not data return.
Do i miss something?

Any help is greatly appreciated.

Thanks
Ivan

Upvotes: 0

Views: 2364

Answers (3)

Niklas
Niklas

Reputation: 30002

You can't fetch normal JSON content from other domains. Have a read about Same origin policy, but the long story short, if you intend to fetch the data from another domain than yours, you need to have it in JSONP format.

As Facebook doesn't provide the Graph API in JSONP format, you will need to either use your own proxy or a proxy like the one Yahoo offers.

Upvotes: 1

mjspier
mjspier

Reputation: 6526

actually Javascript does not allow cross-domain request due the same-domain-policy. If I see it right you try to do so. Better way would be to make the request on the server side.

But there are ways to make cross-domain request in JS. check this: http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/

Upvotes: 1

Anthony Graglia
Anthony Graglia

Reputation: 5435

You can also use /me instead of your name... This should fix it because you need to provide the numeric id and not the custom screen name.

https://developers.facebook.com/docs/reference/api/

Scroll down to the second set of links and click on the first link for friends which will have your access token if you are logged in to Facebook.

Friends: https://graph.facebook.com/me/friends?access_token=...

Upvotes: 1

Related Questions