Set result format of Facebook Graph API to XML instead of JSON

大兔子大兔子 提交于 2019-12-13 03:46:01

问题


I'm trying to change the format of the result i get from the facebook graph api to XML.

I use the format=xml parameter but that don't seem to work for me.

https://graph.facebook.com/me&access_token=xxxxxxxxxxxx&format=xml

The result is shown in Json format :(

Is it still posible to use the xml format?


回答1:


The new graph api always returns data in json.

XML has an overhead on communication size and processing required for parsing so it's being dropped from web API's.




回答2:


That's part of the old api. Graph api will return JSON objects (which, in my opinion, are much better suited for the job anyway). Verbatim from the facebook graph API documentation:

All responses are JSON objects.

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




回答3:


Facebook to XML. Firstly reference Newtonsoft.Json.net

using Newtonsoft.Json;

for example...

var facebookJson = fb.Get("/me");

then...

XmlNode facebookUserObjxml = (XmlNode)JsonConvert.DeserializeXmlNode("{\"root\":" + facebookJson.ToString() + "}", "root");



回答4:


Use this:

$fbInfoUrl = "http://graph.facebook.com/".$token;<br/>
$fbInfo = file_get_contents($fbInfoUrl);<br/>
$fbInfoObj = json_decode($fbInfo, true);<br/>

You'll get an Object in XML format in $fbInfoObj.



来源:https://stackoverflow.com/questions/5540322/set-result-format-of-facebook-graph-api-to-xml-instead-of-json

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