'致命错误:在'PHP PHP应用程序中'找不到'CURLFile'错误'错误'将照片上传到用户的时间线'

 中医鸣芳 发布于 2023-01-18 12:23

我刚刚尝试使用Facebook PHP SDK开发Facebook应用程序.Facebook开发者网站提供的示例代码如下.

         'YOUR_APP_ID',
    'secret' => 'YOUR_APP_SECRET',
    'fileUpload' => true,
    'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
  );

  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();

  $photo = './mypic.png'; // Path to the photo on the local filesystem
  $message = 'Photo upload via the PHP SDK!';
?>

  
  

  api('/me/photos', 'POST', array(
                                         'source' => new CURLFile($photo, 'image/png'),
                                         'message' => $message,
                                         )
                                      );
        echo '
Photo ID: ' . $ret_obj['id'] . '
'; echo '
logout'; } catch(FacebookApiException $e) { // If the user is logged out, you can have a // user ID even though the access token is invalid. // In this case, we'll get an exception, so we'll // just ask the user to login again here. $login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload' )); echo 'Please login.'; error_log($e->getType()); error_log($e->getMessage()); } } else { // No user, print a link for the user to login // To upload a photo to a user's wall, we need photo_upload permission // We'll use the current URL as the redirect_uri, so we don't // need to specify it here. $login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') ); echo 'Please login.'; } ?>

但是当我运行该程序时,它显示错误'Fatal error: Class 'CURLFile' not found'.在搜索解决方案时,我发现新的PHP Facebook SDK没有'CURLFile'类.任何人都可以帮助我使用新的SDK代码'将照片发布到用户时间线'吗?

提前致谢..

1 个回答
  • 也许你需要添加一个反斜杠:

    new \CurlFile($photo)
    

    如果它不起作用可能检查是否CurlFile存在.如果它不存在则需要直接传递tmp filename.fileExtension.

    'source' => class_exists('CurlFile', false) ? new CURLFile($photo, 'image/png') : "@{$photo}"
    

    $photo在其他条件下的形式是filename.fileExtension.

    2023-01-18 12:26 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有