gpt4 book ai didi

php - ' fatal error : Class 'CURLFile' not found' error in Facebook PHP Application for 'upload photo to user' s timeline'

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:56:42 25 4
gpt4 key购买 nike

我刚刚尝试使用 Facebook PHP SDK 开发一个 Facebook 应用程序。 Facebook 开发者网站中给出的示例代码如下。

        <?php
// Remember to copy files from the SDK's src/ directory to a
// directory in your application on the server, such as php-sdk/
require_once('php-sdk/facebook.php');

$config = array(
'appId' => '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!';
?>
<html>
<head></head>
<body>

<?php
if($user_id) {

// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {

// Upload to a user's profile. The photo will be in the
// first album in the profile. You can also upload to
// a specific album by using /ALBUM_ID as the path
$ret_obj = $facebook->api('/me/photos', 'POST', array(
'source' => new CURLFile($photo, 'image/png'),
'message' => $message,
)
);
echo '<pre>Photo ID: ' . $ret_obj['id'] . '</pre>';
echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
} 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 <a href="' . $login_url . '">login.</a>';
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 <a href="' . $login_url . '">login.</a>';

}

?>

</body>
</html>

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

提前致谢..

最佳答案

也许你需要添加一个反斜杠:

new \CurlFile($photo)

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

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

else 条件下的 $photo 格式为 filename.fileExtension

关于php - ' fatal error : Class 'CURLFile' not found' error in Facebook PHP Application for 'upload photo to user' s timeline',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22380580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com