PHP Facebook SDK在页面上发布为Admin

时间:2012-04-19 19:17:07

标签: php facebook post sdk

  

可能重复:
  Facebook Graph Api - Posting to Fan Page as an Admin

我正在尝试在我的网站上提供一个表单,我可以在其中提交博客文章,然后将相同的博客文章发送到我在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 尝试后,它似乎发布到页面墙,但我不是作为页面或管理员。

任何人都知道这只是一个错误还是我做错了什么?

1 个答案:

答案 0 :(得分:1)

您应该再次重新登录您的应用,以便在过期后续订并存储新的访问令牌。 我希望This会帮助你。

相关问题