在php中自动发布facebook

时间:2016-07-05 13:11:06

标签: php facebook-php-sdk

我在Facebook上使用以下代码进行自动发布,但它显示了OAuthException

$user_id = $facebook->getUser();
$page_info = $facebook->api("/PAGE_ID?fields=access_token");

try {
    $ret_obj = $facebook->api(
        '/PAGE_ID/feed', 
        'POST',
        array (
            'link' => 'http://www.example.com/',
            'message' => 'This is a test',
            'access_token'  => $page_info['access_token']
        )
    );
} catch(FacebookApiException $e) {
    $login_url = $facebook->getLoginUrl(array(
        'scope' => 'publish_stream'
    ));
    print_r($e->getType());
    print_r($e->getMessage());
}

错误:

  

致命错误:未捕获OAuthException:(#100)尝试访问   抛出的节点类型(User)上的不存在的字段(access_token)   第1028行/home/malwatal/public_html/basic/lib/base_facebook.php

1 个答案:

答案 0 :(得分:0)

现在是时候使用facebook v5 sdk

$fb = new Facebook\Facebook([
  'app_id' => 'app_id',
  'app_secret' => 'app_secret',
  'default_graph_version' => 'v2.8',
  ]);
             // facebook auto post

$params = array(
  "message" => "$title in $merchant   $short",
  "link" => "http://pickmyoffers.com/",
  "picture" => "http://Pickmyoffers.com/images/searched/Flipkart.png",
  "name" => "www.Pickmyoffers.com",
  "caption" => "www.pickmyoffers.com",
  "description" => "Submit Coupon and earn money through Pickmyoffers.com | Deals,Coupons and offers."
);
            $post = $fb->post('/Page_id/feed',$params, $access_token);
            $post = $post->getGraphNode()->asArray();

}

希望有所帮助