【问题标题】:Facebook PHP SDK v5 Post to Fan PageFacebook PHP SDK v5 发布到粉丝页面
【发布时间】:2016-04-19 02:40:34
【问题描述】:

我想使用 Facebook PHP SDK v5 自动发布到 FAN PAGE。我有下面的代码可以成功发布到我自己的墙上,但是如何更改代码以发布到我的粉丝页面?根据我的阅读,我需要传入粉丝页面的页面ID?

$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'];

我尝试替换这一行:

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

用这个替换粉丝页面ID:

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

并得到错误:

Graph returned an error: Unsupported post request.

更新:我还将应用程序设为“公开”,以试图解决“不支持的发布请求”错误。没有运气。

【问题讨论】:

    标签: php facebook-graph-api


    【解决方案1】:

    我认为您的 $params 不正确。 我用这个:

    $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

    我假设您已经获得了访问令牌,并且访问令牌必须具有 publish_actions 权限才能使其工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-06
      • 2010-11-25
      • 2012-10-24
      • 1970-01-01
      • 2011-05-14
      • 2016-07-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多