简体   繁体   English

通过Facebook API上传照片-路径名问题

[英]uploading photo via facebook API - pathname issues

I'm currently having problems uploading an image via the facebook API - I am not returned any errors via the API and at this time I am thinking it is likely an issue with the file path I am passing in is incorrect. 我目前在通过facebook API上传图像时遇到问题-我没有通过API返回任何错误,目前我认为我传入的文件路径可能不正确。

The image is stored on our server after the user has used the app and I would then like to post it to facebook. 用户使用该应用程序后,该图像将存储在我们的服务器上,然后我想将其发布到Facebook。

My code is below: 我的代码如下:

after running I receive no response from the API whereas if I for instance deliberately changed the oauth_token I'd receive an error (so I know the data is definitely posting) 运行后,我没有收到来自API的响应,但是如果例如我故意更改了oauth_token,则会收到错误消息(因此我知道数据肯定是发布的)

I'm also printing the args array so I can see exactly what I'm posting: 我也在打印args数组,这样我就可以准确看到我发布的内容:

here is the response. 这是回应。

If I navigate to the URL after the @ sign it is broken even if I remove the @C:\\Domains and replace with www. 如果我在@符号后导航到URL,即使删除@C:\\ Domains并替换为www,URL也会损坏。 I have tried passing in the URL that a user could actually navigate to if they were to know the filename 我尝试传递一个URL,以便用户知道文件名时可以实际导航到该URL

eg https://www.example.co.uk/competition/fb/photos/collagetest.jpg 例如https://www.example.co.uk/competition/fb/photos/collagetest.jpg

^ this is a valid link but when passing in the image is still not actually uploaded. ^这是有效的链接,但在传递图像时仍未实际上传。

Any help would be massively appreciated! 任何帮助将不胜感激!

Array ( [message] => Photo from ********[image] => @C:\Domains\******.co.uk\wwwroot\v2\competition\fb\photos\collagetest.jpg )

//upload photo
            $file= './photos/'.basename('collagetest.jpg');
            $args = array(
               'message' => 'Photo from friendbooth',
            );
            $args['image'] = '@' . realpath($file);
            $ch = curl_init();
            $url = 'https://graph.facebook.com/photos?access_token='.$_SESSION['oauth_token'];
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
            $data = curl_exec($ch);
            print_r($args);
            //returns the photo id
            print_r(json_decode($data,true));

            ?>
            <img src="collagetest.jpg" />
            <?

If I navigate to the URL after the @ sign it is broken 如果我在@符号后导航到URL,则该URL损坏

What do you mean by „broken”? “破”是什么意思?

Is that file system path readable from within your PHP script? 从PHP脚本中可以读取该文件系统路径吗? (Please check , don't guess .) (请检查 ,不要猜测 。)

even if I remove the @C:\\Domains and replace with www. 即使我删除@C:\\ Domains并替换为www。 I have tried passing in the URL 我尝试传递URL

Giving a URL in this place is nonsense – a file system path is expected here. 在这个地方提供URL是胡说八道-这里应该有文件系统路径。 (Are you aware of the difference between the two?) (您知道两者之间的区别吗?)

turns out it was nothing to do with the file path in the end! 原来与文件路径无关!

adding

            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

completely resolved the issue! 彻底解决了问题! Hope this helps someone else in future. 希望这对以后的人有所帮助。 if posting to HTTPS urls try adding the above in if you aren't getting ANY response (error messages etc mean you are getting a response) 如果发布到HTTPS url,请尝试在没有任何响应的情况下添加以上内容(错误消息等表示您正在响应)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM