dtnpf35197 2015-11-07 15:11
浏览 22

Facebook PHP SDK v5发布到粉丝专页

I would like to use the Facebook PHP SDK v5 to automatically post to a FAN PAGE. I have the code below which successfully posts to my own wall, but how do I alter the code to post to my fan page? From what I've read, I need to pass in the page id of the fan page?

$params["message"] = 'test';
$params["link"] = 'https://example.com';
$params["picture"] = 'https://example.com/images/logo_hod.jpg';
$params["description"] = 'testtt';

$access_token = $accessToken;

try {
    $response = $fb->post('/me/feed', $params, $access_token);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
}

$graphNode = $response->getGraphNode();

echo 'Posted with id: ' . $graphNode['id'];

I tried replacing this line:

$response = $fb->post('/me/feed', $params, $access_token);

with this to substitute in the fan page id:

$response = $fb->post('/229107363768165/feed', $params, $access_token);

and got the error:

Graph returned an error: Unsupported post request.

UPDATE: I also made the app "public" in an attempt to get past the "unsupported post request" error. No luck.

  • 写回答

1条回答 默认 最新

  • dongtan7201 2016-02-05 20:39
    关注

    i think your $params is not right. I use this:

    $fb = new Facebook\Facebook([
      'app_id' => '{app-id}',
      'app_secret' => '{app-secret}',
      'default_graph_version' => 'v2.2',
      ]);
    
    $params = [
      'link' => 'https://example.com',
      'photo' => 'https://example.com/images/logo_hod.jpg',
      'message' => 'A test post!',
    ];
    
    try {
      // Returns a `Facebook\FacebookResponse` object
      $response = $fb->post('/me/feed', $params, '{access-token}');
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
      echo 'Graph returned an error: ' . $e->getMessage();
      exit;
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
      echo 'Facebook SDK returned an error: ' . $e->getMessage();
      exit;
    }
    

    Post Links Using the Graph API

    I assumes that you've already obtained an access token and the access token must have the publish_actions permission for this to work.

    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数