Determining type of object with id in FB Graph API

这一生的挚爱 提交于 2019-12-04 07:59:40

问题


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


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/8960911/determining-type-of-object-with-id-in-fb-graph-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!