我的网络服务器上有照片,现在,我要把它上传到粉丝页面相册。照片上传有任何限制。上传到粉丝页面相册后,我要将其发布到壁。
// Get the page access token
$accounts = $facebook->api('/my_account_id/accounts', 'GET', $params);
$data = $accounts['data'];
foreach($data as $account) {
if( $account['id'] == $fanpage || $account['name'] == $fanpage )
$fanpage_token = $account['access_token'];
}
// Get all albums from the page
// Must use app access token, not page token!
// You can also use a static album id to test
$fanpage_albums = $facebook->api($fanpage . '/albums', 'GET', $params);
$albums = $fanpage_albums['data'];
$sorted = array();
foreach($albums as $album) {
if( ! strpos($album['name'], 'Special') )
continue;
$sorted[] = $album;
}
$album_id = $sorted[0]['id']; // Get the first one. Shouldn't be empty!
// Upload the photo (previously uploaded by user)
$args = array(
'message' => 'Von ' . $teilnehmer_name,
'image' => '@' . realpath($path. $_FILES['media']['name']),
'aid' => $album_id,
'no_story' => 1 // Nicht auf der Wall anzeigen (Thank God for that),
'access_token' => $fanpage_token // note, we use the page token here
);
$photo = $facebook->api($album_id . '/photos', 'post', $args);
if( is_array( $photo ) && ! empty( $photo['id'] ) )
echo 'Photo uploaded. Check it on Graph API Explorer. ID: ' . $photo['id'];
我尝试了上面的代码,但它无效。
答案 0 :(得分:1)
不要使用realpath()
,使用文件夹名称/文件名,它将起作用,然后您需要一个页面访问令牌。