简体   繁体   English

PHP-FB照片/视频上传问题

[英]PHP - FB photo/video upload issue

I'm working on a web site that has to upload some videos and photos on my personal FB page. 我在一个网站上工作,该网站必须在我的个人FB页面上上传一些视频和照片。

I'm using the PHP SDK v4, and I registered my test App on FB (called CountLikes). 我正在使用PHP SDK v4,并在FB上注册了测试应用程序(称为CountLikes)。 Trying and trying again, I finally made a simple post on my wall, so at the moment I want to upload an image on my profile. 经过反复尝试,我终于在墙上发布了一个简单的帖子,因此目前我想在个人资料中上传图片。

I copied the code written here, changing filename and path: https://developers.facebook.com/docs/php/howto/uploadphoto/4.0.0 我复制了此处编写的代码,更改了文件名和路径: https : //developers.facebook.com/docs/php/howto/uploadphoto/4.0.0

I don't get any error message, but the code is not working fine. 我没有收到任何错误消息,但是代码无法正常工作。 When I check on my profile I see that there is a new album called "CountLikes Album", but inside there is no photo. 查看个人资料时,我看到有一个名为“ CountLikes Album”的新相册,但是里面没有照片。

The Access Token I use has all the possible permission (I will select the right ones when I will do this upload). 我使用的访问令牌具有所有可能的权限(我将在进行此上载时选择正确的访问令牌)。

I post here the code I written (APPID, APPSECRET and TOKEN are written correctly in the original code): could you help me? 我在这里发布了我编写的代码(APPID,APPSECRET和TOKEN用原始代码正确编写了):您能帮我吗?

<?php
define('FACEBOOK_SDK_V4_SRC_DIR', 'Z:/Sito/FB/facebook-php-sdk-v4-4.0-dev/src/Facebook/');
require __DIR__ . '/facebook-php-sdk-v4-4.0-dev/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
FacebookSession::setDefaultApplication('APPID','APPSECRET');
FacebookSession::enableAppSecretProof(false);
$session = new FacebookSession('TOKEN');
if($session) 
{
  try 
  {
    $response = (new FacebookRequest(
  $session, 'POST', '/me/photos', array(
    'source' => new CURLFile('Z:\Sito\FB\test.jpg', 'image/png'),
    'message' => 'User provided message'
  )
))->execute()->getGraphObject();
echo "Posted with id: " . $response->getProperty('id');
  } 
   catch(FacebookRequestException $e) 
   {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
}
}
?>

Thanks in advance! 提前致谢!

The issue might be with this line: 问题可能与以下行有关:

'source' => new CURLFile('Z:\Sito\FB\test.jpg', 'image/png'),

You are setting the type as png and uploading jpg . 您将类型设置为png并上传jpg Update that and see if it works. 更新它,看看它是否有效。

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

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