16
我使用Facebook PHP SDK 3.0.1(當前最新版本)。 我需要做的是將頁面標識作爲頁面的標識進行發佈。發佈到Facebook頁面作爲頁面(不是一個人)
我試着用我從頁面獲得的access_token替換access_token(/ me/accounts),但是現在說的令牌由於某種原因是無效的。 Facebook的「模仿」頁面現在脫機,並且我在API中看不到任何有關做我想做的事情的信息..也許我迷路了,或者可能看不到正確的方向。 .php我修改並用于歸檔:
require '../src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
));
// Get User ID
$user = $facebook->getUser();
//Lists all the applications and pages
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$accounts_list = $facebook->api('/me/accounts');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
$page_selected = 'xxxxxxxxxxxx';
$page_access_token = $accounts_list['data']['0']['access_token'];
echo 'page_access_token:' . $page_access_token;
<?php
if (isset($_GET['publish'])){
try {
$publishStream = $facebook->api("/$page_selected/feed", 'post', array(
'access_token' => '$page_access_token',
'message' => 'Development Test message',
'link' => 'http://xxxxxxx.com',
'picture' => 'http://xxxxxx/xxxx_logo.gif',
'name' => 'xxxxxxxx Goes Here',
'description'=> 'And the exciting description here!'
)
);
//as $_GET['publish'] is set so remove it by redirecting user to the base url
} catch (FacebookApiException $e) {
echo($e);
echo $publishStream;
echo 'catch goes here';
}
}
?>
因爲我無法回答我自己的問題,所以我編輯了這個問題。
貫穿整個API去了..
解決方法:
張貼之前,你需要你設置的access_token到一個頁面擁有的頁面。
$facebook->setAccessToken($page_access_token);
做到了這一點,後來一切都因爲它通常會被預期的,沒有必要修改後的功能,並添加「的access_token」選項後。
方式太多的代碼讓我閱讀 – Ibu 2011-06-04 21:23:11
對不起,修剪了代碼。 – tictac 2011-06-04 21:26:02
本教程應該有所幫助。它顯示瞭如何列出帳戶中的網頁:http://net.tutsplus.com/tutorials/php/wrangling-with-the-facebook-graph-api/comment-page-1/#comment-390691 – LeeTee 2011-12-13 17:04:12