我使用Facebook图形api使用codeigniter从我的网站上传Facebook中的照片。 但多次在脸书中上传了相同的图片。 我的代码如下:
# Path to facebook's PHP SDK.
require_once(APPPATH."libraries/facebook.php");
# Facebook application config.
// newcheck app [testpurpose ....]
$config = array(
'appId' => 'APP ID',
'secret' => 'SECRET KEY',
'fileUpload' => true # Optional and can be set later as well (Using setFileUploadSupport() method).
);
# Create a new facebook object.
$facebook = new Facebook($config);
# Current user ID.
$user_id = $this->facebook->getUser();
# Check to see if we have user ID.
if($user_id) {
# If we have a user ID, it probably means we have a logged in user.
# If not, we'll get an exception, which we handle below.
try {
# Get the current user access token:
$access_token = $this->facebook->getAccessToken();
# Upload photo to the album we've created above:
$image_absolute_url = 'http://abc.com/research_social_sites/figures/pie.jpg';
$photo_details = array();
$photo_details['access_token'] = $access_token;
$photo_details['url'] = $image_absolute_url; # Use this to upload image using an Absolute URL.
$photo_details['message'] = 'Your picture message/caption goes here'. date('Y-m-d H:i:s') .'->BY RLS';
$upload_photo = $this->facebook->api('/me/photos', 'POST', $photo_details);
# Output photo ID:
echo '<br>Photo ID: ' . $upload_photo['id'];
} 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 = $this->facebook->getLoginUrl( array('scope' => 'publish_stream, user_photos'));
echo 'Error Uploading Image <br> Please <a href="' . $login_url . '">login.</a>';
}
} else {
# No user, print a link for the user to login and give the required permissions to perform tasks.
$params = array(
'scope' => 'publish_stream, user_photos', # These permissions are required in order to upload image to user's profile.
);
$login_url = $this->facebook->getLoginUrl($params);
echo 'You are not Logged in <br> Please <a href="' . $login_url . '">login.</a>';
}
但它工作正常,但主要问题是它上传文件不止一次相同的图像。 所以请帮助我提供解决方案,停止多次在Facebook上传图像。 感谢您的合作。