Exception when uploading photo with Facebook Graph API

大憨熊 提交于 2019-11-30 10:17:24

I'm so glad I went trough the same problem You have to set the fileUpload param to true !

$facebook = new Facebook(array(
            'appId'  => $facebookapi_id,
            'secret' => $facebookapi_secret,
            'fileUpload' => true,
            'cookie' => true
          ));  

Facebook have intentionally transformed the POST fields to a GET string using http_build_query() to stop fields beginning with @ being used to accidentally or maliciously to upload files. Here's the GitHub issue.

A quick fix for this is to remove the http_build_query() from src/facebook.php in the SDK:

$opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');

Becomes:

$opts[CURLOPT_POSTFIELDS] = $params;

However if you do this you should take action to filter user generated messages that start with @. For example you could add a space to the front of each message.

If you use graph api to upload the photo it will getting the error (#200) User must have accepted TOS.

However if you use old rest api, just changing the url to https://api.facebook.com/method/photos.upload?access_token=xXXXXXXXXXXX if you use above example.

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