Determining type of object with id in FB Graph API
Asked Answered
Z

2

25

Is there a way to determine what kind of object is represented by the given ID https://graph.facebook.com/ID. When I'm requesting this in Graph API Explorer tool, in the response there is a field named type, that could contain user, page, album, photo and so on. But when I'm requesting the same from browser or via SDK, in response there is no such field, but everything else is the same. And I have to guess what kind of object I have relying on other fields: for example if there is a field gender that means that I have user object. I think this is a bug in FB Graph API. Is there any solution for this?

You can see the differences on the screenshots the response of graph api explorer tool the response from my browser

Zebra answered 22/1, 2012 at 12:5 Comment(2)
Exactly what i was looking for few days. FB documentation is crap one.Cher
Apparently this data is no longer available in the newer versions of Graph Api. 2.3 is the last version with all the data.Chickasaw
S
49

This is possible if you using something Facebook call "introspection" by adding metadata argument to your request:

GET http://graph.facebook.com/object_id?metadata=1

The result will contain type field

Staircase answered 22/1, 2012 at 19:15 Comment(5)
thanks a lot :) I just added metadata=1 at the end and now it works fineZebra
It may be a little late but for newcomers, you can save bandwidth by specifing only the type field of metadata by using ?metadata=1&fields=picture,metadata.fields(type)Cosmonaut
FB api is the messiest API I worked with... For "image" and "link" metadata won't return type but you can get type via "fields=type", but for "video" it will return an error, for "video" you must get type via metadata... ><Constitutionality
I spent the last couple of minutes searching for this in the official graph api docs. Did not find anything … if someone's luckier than me, I'd very much appreciate a link from an official resource.Pironi
@panepeter, it was never properly documented in the new docs, but it's here from early graph api versionsStaircase
Z
14

You can add metadata=1 and response will have metadata: {type: ...} if you do request like that:

http://graph.facebook.com/object_id?metadata=1&fields=id,name,metadata{type}

Based on commend of Vinicius Tavares.

Zebapda answered 3/9, 2015 at 7:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.