Facebook Graph API - get ID for a URL?
Asked Answered
H

6

20

This seems like a pretty obvious, basic thing to expect from the Graph API, but I'm having serious difficulty with it. All I want to do is get the ID for any particular URL. They have a method for this:

https://graph.facebook.com/?ids=http://www.imdb.com/title/tt0117500/

And that works great. But if I try another URL, say for my blog,

https://graph.facebook.com/?ids=http://dusda.vox.com

it doesn't give me back a numerical ID like all of the examples do. Instead, this:

{"http:\/\/dusda.vox.com":{"id":"http:\/\/dusda.vox.com"}}

If I try to use that "id", I get jack (probably because the query string looks impossible to parse):

Request: https://graph.facebook.com/http://dusda.vox.com/likes
Response: {"id":"http:\/\/dusda.vox.com\/likes"}

So what's up with this? Is the Graph API just selectively reliable, or am I misunderstanding something? I've tried it on URLs that I know are popular on Facebook, too, and I've gotten mixed results.

Horsa answered 27/8, 2010 at 5:14 Comment(1)
Old question, still no solution? I tried cnn.com, works fine in the debugger, but does not return the ID using the API...Pileous
C
8

The ID is given by Facebook only to pages which have a fbshare/like button. Else the API returns the number of shares and the request URL.

Christalchristalle answered 31/8, 2010 at 12:24 Comment(2)
graph.facebook.com/?id=http://www.huffingtonpost.com/2011/06/14/… has a Like button but the link still gives back limited information. Both pages has a fb:app_id in the <head> section.Exhalant
Is this behaviour documented somewhere?Soakage
D
10

Try FQL for this;

http://graph.facebook.com/fql?q=select%20url%2C%20id%2C%20type%2C%20site%20from%20object_url%20where%20url%20%3D%20%22http%3A%2F%2Fkriek.hu%2F%22

returns:

{
   "data": [
      {
         "url": "http://kriek.hu/",
         "id": 497425470154,
         "type": "link",
         "site": "kriek.hu"
      }
   ]
}

For more information, see object_url.

I hope it helps!

Deckle answered 3/1, 2012 at 10:37 Comment(3)
With this you get id which is useful. +1Pork
I don't know about you, but the ID I get is not valid (not even in the debugger).Pileous
FQL is being deprecated.Upmost
C
8

The ID is given by Facebook only to pages which have a fbshare/like button. Else the API returns the number of shares and the request URL.

Christalchristalle answered 31/8, 2010 at 12:24 Comment(2)
graph.facebook.com/?id=http://www.huffingtonpost.com/2011/06/14/… has a Like button but the link still gives back limited information. Both pages has a fb:app_id in the <head> section.Exhalant
Is this behaviour documented somewhere?Soakage
I
4

If I use the facebook object debugger page I can scrape every url, for example:

https://developers.facebook.com/tools/debug/og/object?q=ddnl.de

The page give me back an url with ID and so I can get every needed parameters.

In this case https://graph.facebook.com/10150164108649475

But I don't get this ID or url with FQL or otherwise?

Intercede answered 23/3, 2012 at 9:23 Comment(0)
P
3

Very old question, but here's what I found works for me as none of the answers here really resolved my issue:

If you have a custom object tied to a url, the method suggested by Pepe only gives the id FB assigns to the url where type=link. (Which is not tied to any comments)

In my case, I need my custom object id so that I could pull associated comments from it. You can get the object id using FQL by doing a select on 'comments_fbid' from the 'link_stat' table. (This will return the object id even if no comments have been added so it should work for other cases)

api.facebook.com

Persian answered 21/9, 2012 at 23:23 Comment(0)
F
2

At this time no of the suggested solutions work for all urls. Only the Debugger is able to get the Graph ID correctly

For example

Debugger: https://developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fwww.amazon.de%2Fgp%2Fproduct%2F3810510793%2F

For URL: www.amazon.de/gp/product/3442465583/

Result: https://graph.facebook.com/10150771435736113

{
   "url": "http://www.amazon.de/dp/3810510793/ref=tsm_1_fb_lk",
   "type": "book",
   "title": "Die unwahrscheinliche Pilgerreise des Harold Fry: Roman",
   "image": [
      {
         "url": "http://ecx.images-amazon.com/images/I/51I4E81xrRL._SL160_.jpg"
      }
   ],
   "description": "Die unwahrscheinliche Pilgerreise des Harold Fry: Roman",
   "site_name": "Amazon.de",
   "updated_time": "2012-12-19T16:54:27+0000",
   "id": "10150771435736113",
   "application": {
      "id": "164734381262",
      "name": "Amazon",
      "url": "https://www.facebook.com/apps/application.php?id=164734381262"
   }
}
Fabrianne answered 19/12, 2012 at 17:0 Comment(0)
S
0

I had the same problem here, I was trying to get the same data IMDB gets. After almost bang my head against the wall, I decided to look at the facebook's js function. And look what I get, the explanation is on the link.

Getting limited data from a page which has a Facebook ID

Peace

Shannanshannen answered 23/10, 2012 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.