Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining type of object with id in FB Graph API

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 toolthe response from my browser

like image 437
haynar Avatar asked Jan 22 '12 12:01

haynar


People also ask

What data can I get from Facebook Graph API?

The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.

How do I get my Facebook Graph API User ID?

The simplest way to get a copy of the User Profile object is to access the /me endpoint: FB. api('/me', function(response) { }); This will this will return the users name and an ID by default.

Is Facebook Graph API deprecated?

API Version Deprecations: As part of Facebook's Graph API and Marketing API, please note the upcoming deprecations: August 3, 2021: Graph API v3. 3 will be deprecated and removed from the platform. August 25, 2021 Marketing API v9.


2 Answers

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

like image 68
Juicy Scripter Avatar answered Oct 22 '22 09:10

Juicy Scripter


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.

like image 14
JLarky Avatar answered Oct 22 '22 11:10

JLarky