使用API​​(php)将相册添加到页面

时间:2011-09-15 13:19:54

标签: php facebook-graph-api

我正在尝试为网页创建相册,但是我收到以下错误;

[15-Sep-2011 22:38:14] PHP致命错误:未捕获OAuthException:(#100)相册所有者的ID无效   在第988行的C:\ inetpub \ wwwroot \ Diveengine \ v3 \ facebook \ base_facebook.php中抛出

代码如下

require 'facebook.php';
$facebook = new Facebook(array(
    'appId'  => "aaaaaaaaaaaa",
    'secret' => "aaaaaaaaaaaaaaaaaaaaa",
));

$facebook->setAccessToken("aaaaaaaaaaaaaaaaaaaaa");

$me = $facebook->api('/me');


//At the time of writing it is necessary to enable upload support in the Facebook SDK, you do this with the line:
$facebook->setFileUploadSupport(true);



//Create an album
$album_details = array(
        'message'=> 'test album',
        'name'=> 'Test Album'
);
$create_album = $facebook->api('/pageid/albums', 'post', $album_details);
// I have the page ID

//Get album ID of the album you've just created
$album_uid = $create_album['id'];

我已经能够为我的个人资料创建一个专辑,但是我希望这个页面能用于该页面。

1 个答案:

答案 0 :(得分:4)

好的伙计,花了很长时间来搞清楚这一点,但是这里有。你的代码可能很好,但诀窍是获得正确的访问令牌。最初,我认为我必须创建一个页面访问令牌(使用图形api资源管理器),其中包含允许我做我想要的所有装饰。

事实证明,您需要做的就是:

1)转到https://developers.facebook.com/tools/explorer 2)它可能会自动填充你的脸书ID,但在那里贴上/帐户,所以它看起来像这样:

#yourfacebookidnumber / accounts

或者您可以将其更改为

https://graph.facebook.com/me/accounts

您将获得一个JSON转储,其中列出了您是管理员的所有粉丝页面。找到您要发布的粉丝页面(您需要成为该粉丝页面的管理员)。

抓住那里指定的访问令牌,在你的代码中使用它,Bob就是你的叔叔!