0
tutorial已幫助我編寫以下代碼;有了它,我可以將照片上傳到粉絲頁面上的相冊中。我怎樣才能做到這一點,以便我可以發佈到粉絲頁面牆上,而不是將照片上傳到相冊中?我正在尋找在下面實現所需的代碼。使用php將照片上傳到Facebook粉絲頁面牆
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once 'library/facebook.php';
$facebook = new Facebook(array(
'appId' => 'My APP ID',
'secret' => 'My Secret KEY',
'fileUpload' => true
));
#It can be found at https://developers.facebook.com/tools/access_token/
#Change to your token.
$access_token = 'My access token';
$params = array('access_token' => $access_token);
#The id of the fanpage
$fanpage = 'My Fan Page ID';
#The id of the album
$album_id ='My Album ID';
$accounts = $facebook->api('/My User Name/accounts', 'GET', $params);
foreach($accounts['data'] as $account) {
if($account['id'] == $fanpage || $account['name'] == $fanpage){
$fanpage_token = $account['access_token'];
}
}
$valid_files = array('image/jpeg', 'image/png', 'image/gif');
if(isset($_FILES) && !empty($_FILES)){
if(!in_array($_FILES['pic']['type'], $valid_files)){
echo 'Only jpg, png and gif image types are supported!';
}else{
$img = realpath($_FILES["pic"]["tmp_name"]);
$args = array(
'message' => 'This photo was uploaded via WebSpeaks.in',
'image' => '@' . $img,
'aid' => $album_id,
'no_story' => 1,
'access_token' => $fanpage_token
);
$photo = $facebook->api($album_id . '/photos', 'post', $args);
if(is_array($photo) && !empty($photo['id'])){
echo '<p><a target="_blank" href="http://www.facebook.com/photo.php?fbid='.$photo['id'].'">Click here to watch this photo on Facebook.</a></p>';
}
}
}
?>
<div class="main">
<p>Select a photo to upload on Facebook Fan Page</p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<p>Select the image: <input type="file" name="pic" /></p>
<p><input class="post_but" type="submit" value="Upload to my album" /></p>
</form>
</div>
原因'發佈到轉頁扇牆,不只是將照片上傳到album'什麼;差異? –
上面的代碼會將照片上傳到相冊,而不會在實際牆上發佈相同的照片。只需將其上傳到相冊中,而無需在牆上顯示照片 –
每當您上傳照片時,照片都會發布在牆上。你不必爲那個 –