2016-07-05 61 views
0

我正在使用以下代碼在Facebook上進行自動發佈,但它顯示我OAuthException自動發佈facebook在php中

$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()); 
} 

錯誤:

Fatal error: Uncaught OAuthException: (#100) Tried accessing nonexisting field (access_token) on node type (User) thrown in /home/malwatal/public_html/basic/lib/base_facebook.php on line 1028

+0

。而你的問題是什麼? – Jer

+0

我該如何解決它 –

+0

'$ page_info ['access_token']'不存在 – Lee

回答

0

現在是時候使用Facebook SDK V5

$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(); 

} 

希望這有助於