我需要以这种方式使用php cronjob将照片上传到粉丝页墙。
http://i48.tinypic.com/kcgwo5.jpg
我拥有权限令牌并尝试了几种方法但没有成功。
test1.php:
$page_access_token = 'accesstoken';
$page_id = 'idofmyfanpage';
$data['picture'] = 'urlofimage';
$data['access_token'] = $page_access_token;
$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);
echo $return;
但结果......
http://i46.tinypic.com/5l5hfq.png
这个灰色的盒子......
我尝试了另一种方式。
test2.php:
$page_access_token = 'accesstoken';
$page_id = 'idofmyfanpage';
$data['image'] = '@imagetoupload.jpg';
$data['access_token'] = $page_access_token;
$post_url = 'https://graph.facebook.com/'.$page_id.'/photos';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);
echo $return;
但请将照片上传到我的个人资料墙。
我还尝试上传粉丝页时间线专辑。
http://graph.facebook.com/mypage/albums
{
"data": [
{
"id": "xxxxxxxxxxxxxxxxxxxxxxx",
"from": {
"category": "Community",
"name": "xxxxxxxxxxxxxxx",
"id": "xxxxxxxxxxxxxx"
},
"name": "Timeline Photos",
"link": "http://www.facebook.com/album.php?fbid=xxxxxxxxxxxxxxxx&id=xxxxxxxxx&aid=xxxx",
"cover_photo": "xxxxxxxxxxxxxx",
"count": 1,
"type": "wall",
"created_time": "xxxxxxxxxxxxx",
"updated_time": "xxxxxxxxxxxxx",
"can_upload": false
},
{
"id": "xxxxxxxxxxxxxxxxxx",
"from": {
"category": "Community",
"name": "xxxxxxxxxxx",
"id": "xxxxxxxxxxxxxxx"
},
"name": "Profile Pictures",
"link": "http://www.facebook.com/album.php?fbid=xxxxxxxxxx&id=xxxxxxxxx&aid=xxxxxxx",
"cover_photo": "xxxxxxxxxxxxxxx",
"count": 1,
"type": "profile",
"created_time": "xxxxxxxxxxxxxxx",
"updated_time": "xxxxxxxxxxxxxxx",
"can_upload": false
}
]
}
test3.php
$page_access_token = 'accesstoken';
$page_id = 'idofmyfanpage';
$data['image'] = '@imagetoupload.jpg';
$data['access_token'] = $page_access_token;
$post_url = 'https://graph.facebook.com/idofalbum/photos';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);
echo $return;
结果:
{"error":{"message":"(#120) Invalid album id","type":"OAuthException","code":120}}
我怎么能?
PD:抱歉我的英语不好。