Facebook graph api - why using async ajax file upload i cannot get the photo id response?

浪尽此生 提交于 2019-12-23 05:10:50

问题


Im using the iframe techinique to upload a photo to the facebook graph api. im using this technique: http://www.openjs.com/articles/ajax/ajax_file_upload/response_data.php.

The photo gets uploaded sucessfully. But i NEED to read the response it gives to me on my iframe, but im not being able to do it. I tried every technique i know, pure javascript and jquery hacks.. but nothing works...

the format of the response is the following (i can see this on chrome js console ):

{
   "id": "111346062333977",
   "post_id": "100003757518505_111258412342742"
}

what is that format? how can i read it? its not on the DOM, its not on the body, its nowere!!!!


回答1:


The response from Graph API are always JSON encoded (unless callback parameter specified, in that case it's JSONP).

You will not be able to get that response in a flow you trying to implement. If you doing direct upload of photo to Graph API from client-side response will be subject of cross-domain policy and your JavaScript simply have no access to the response.

You should upload the image from server side to be able to retrieve response which contain uploaded photo id




回答2:


If I understand your problem then you came across the Same origin policy since you post the form into an iframe, and the action of the form is to another domain, different than yours (the one in which the main page is loaded from).

Because of that, the response you get in the iframe can not be then passed to the parent page since they don't share the same domain and the browser blocks the communication.

As @JuicyScripter wrote you might want to think about posting the image from the server side which will make things simpler. If how ever you don't want to give up on the client side solution so quickly, I suggest you check this thread: Facebook Graph API - upload photo using JavaScript



来源:https://stackoverflow.com/questions/10221588/facebook-graph-api-why-using-async-ajax-file-upload-i-cannot-get-the-photo-id

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