1

我需要以这种方式使用 php cronjob 将照片上传到粉丝页面墙上。

http://i48.tinypic.com/kcgwo5.jpg

我拥有具有权限的令牌并尝试了多种方法但均未成功。

测试1.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

这个灰色的盒子...

我尝试了另一种方式。

测试2.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:对不起我的英语不好。

4

0 回答 0