【发布时间】:2012-04-19 19:17:06
【问题描述】:
我正在尝试在我的网站上创建一个表单,我可以在其中提交博客文章,然后将相同的博客文章发送到我在 facebook 上的页面。
我的页面是:https://www.facebook.com/foreveraloneminecraft
我希望它像我已登录并手动发布一样发布它(就像那里的所有其他帖子一样)。
我一直在到处搜索,但我发现的所有内容要么从未真正发布过任何内容,要么引发错误。
这是我搜索完后得到的结果:
<?php
include('core/init.inc.php');
require_once('libs/parser.php'); // path to Recruiting Parsers' file
$parser = new parser; // start up Recruiting Parsers
if(isset($_POST['submit'], $_POST['user'], $_POST['title'], $_POST['body'])
{
//--- Facebook Posting ------
require_once('libs/facebook/facebook.php');
$appid = '286964398044671';
$appsecret = 'myappsecret';
$pageid = '215852885143861';
$token = 'mytoken';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => $appsecret,
));
// Get the current access token
//$token = $facebook->getAccessToken();
//Information that makes up the facebook page post
$attachment = array(
'access_token' => $token,
'message' => $_POST['body'],
'link' => 'http://hgs1957.hostedd.com/news.php',
'picture' => 'http://hgs1957.hostedd.com/images/foreverAloneMCguy.png',
'name' => $_POST['title'],
'description'=> 'Latest news for foreveralonemc.com.'
);
//Try to post to the facebook page
try{
$res = $facebook->api('/'.$pageid.'/feed','POST',$attachment);
} catch (Exception $e){
echo $e->getMessage();
}
//Add the post to the sql database of posts
//add_post($_POST['user'], $_POST['title'], $_POST['body']);
//Redirect to news feed
header('Location: news.php');
die();
}
?>
我使用令牌中的 appsecret 是我在使用 https://developers.facebook.com/tools/explorer/ 时获得的权限:publish_stream、status_update、manage_pages、publish_actions、offline_access 尝试后它似乎发布到页面墙上,但我不是页面或管理员。
有人知道这只是一个错误还是我做错了什么?
【问题讨论】:
-
好的,我发现这是因为我使用的访问令牌是我自己的,而不是我的页面。所以我使用同一个资源管理器并使用 /accounts 获得了我的页面访问令牌。唯一的问题是我读取用户访问令牌在 60 天后过期,因此页面访问令牌。万一它过期了,我该怎么办呢?