![](/img/trans.png)
[英]Fatal error: Uncaught Error: Call to undefined method Facebook\Facebook::getUser()
[英]Why I get that error Call to undefined method Facebook\Facebook::api()?
我嘗試使用facebook SDK PHP發布到Facebook頁面的鏈接,而嘗試我的代碼時卻收到“調用未定義方法Facebook \\ Facebook :: api()”,但我不知道這是我第一次工作是什么錯誤使用facebook SDK。 我正在使用facebook-php-sdk-v4-5.0.0
我的代碼是:
<?php
session_start();
require_once("FacebookSDK/src/Facebook/autoload.php");
use Facebook\Facebook;
$config = array_merge([
'app_id' => 'APP_ID',
'app_secret' => 'SECRET',
'enable_beta_mode' => false,
'http_client_handler' => null,
'persistent_data_handler' => null,
'pseudo_random_string_generator' => null,
'url_detection_handler' => null,
]);
$fb = new Facebook($config);
$params = array(
"access_token" => "TOKEN",
"message" => "Here is a blog post about auto posting on Facebook using PHP #php #facebook",
"link" => "http://example.com/",
"picture" => "http://example.com/image1.jpg",
);
try {
$ret = $fb->api('/ID/feed', 'POST', $params);
echo 'Successfully posted to Facebook';
} catch(Exception $e) {
echo $e->getMessage();
}
?>
facebook方法在這里是不同的。 使用下面的代碼
$ret = $fb->post('/page_id/feed',$params, $pageaccesstoken );
代替
$ret = $fb->api('/ID/feed', 'POST', $params);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.