发布facebook api不作为页面

时间:2015-04-07 10:55:39

标签: facebook facebook-graph-api

我已经制作了facebook应用程序,获得了appID和秘密,我正在尝试将页面发布到页面。我已经授予了应用程序权限。

但是当我发帖时,新帖子会创建“作为用户”,而不是页面。

我的代码:

require '../lib/fb/autoload.php';

use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;

FacebookSession::setDefaultApplication('APP_ID','SECRET');

$session = new FacebookSession('ACCESS_TOKEN');


try {
  $response = (new FacebookRequest(
            $session, 'POST', '/1429642034012499/feed', array(
                'message'       => 'test',
                'link'          => 'http://mylink',
            )
        ))->execute()->getGraphObject();

        print_r($response);
} catch (FacebookRequestException $e) {
   echo "Exception occured, code: " . $e->getCode();
        echo " with message: " . $e->getMessage();

} catch (\Exception $e) {

}

Page查看。

1 个答案:

答案 0 :(得分:0)

本答案适用于使用.NET Facebook API库的C#。但是在PHP中,Logic应该是相同的。

您必须获取页面访问令牌:

转到此处:developers.facebook.com/tools /

然后转到此链接:

enter image description here

然后点击:“Get Access Token

然后添加这些权限:

enter image description here

然后复制新访问令牌:

enter image description here

现在在C#Class I中(这是POST A Comment as Page):

var userClient = new FacebookClient("THE NEW ACCESS TOKEN YOU JUST GENERATED");

dynamic accountInfo = userClient.Get("USER_ID" + "/accounts"); 

//USER_ID Should be Digits, this is the UserID when you do: facebook.com/USERID it should come up with the Admin Profile

var pageAccessToken = accountInfo.data[0].access_token;

var pageClient = new FacebookClient(pageAccessToken);

dynamic parameters = new ExpandoObject();
parameters.message = model.Message;

dynamic pageResult = pageClient.Post(string.Format("{0}/comments",), parameters);