I just tried to develop a Facebook application using the PHP PHP SDK. An example code is provided on the Facebook developer site below.
<?php
require_once('php-sdk/facebook.php');
$config = array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
'fileUpload' => true,
'allowSignedRequest' => false
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$photo = './mypic.png';
$message = 'Photo upload via the PHP SDK!';
?>
<html>
<head></head>
<body>
<?php
if($user_id) {
try {
$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) {
$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 {
$login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') );
echo 'Please <a href="' . $login_url . '">login.</a>';
}
?>
</body>
</html>
But when I run the program, it shows an error 'Fatal error: Class 'CURLFile' not found'. When you were looking for a solution, I found that the new PHP Facebook SDK does not have a CURLFile class. Can someone help me with a new SDK code to “send a photo to the user's timeline”?
Thanks in advance.
source
share