![](/img/trans.png)
[英]Call to undefined method Facebook\FacebookRequest::getGraphNode()
[英]Call to undefined method Facebook\FacebookRequest::execute()
這是我使用facebook圖譜API在facebook組中發布帖子的代碼。但它返回錯誤。
方法1
include 'vendor/autoload.php';
use Facebook\FacebookApp;
use Facebook\Facebook;
use Facebook\FacebookRequest;
$app_id = 'xxxxxxxxxxxxxxx';
$psswd = 'xxxxxxxxxxxxxxx';
$group_id = 'xxxxxxxxxxxxxxx';
$app = new FacebookApp($app_id, $psswd);
$request = new FacebookRequest(
$app,
'POST',
'/'.$group_id.'/feed',
array (
'message' => 'This is a test message',
)
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
錯誤
致命錯誤:調用未定義的方法Facebook \\ FacebookRequest :: execute()
方法2
session_start();
error_reporting(-1);
ini_set('display_errors', 1);
include 'vendor/autoload.php';
use Facebook\FacebookApp;
use Facebook\Facebook;
use Facebook\FacebookRequest;
$app_id = 'xxxxxxxxxxxx';
$psswd = 'xxxxxxxxxxxx';
$group_id = 'xxxxxxxxxxxx';
$fb = new Facebook([
'app_id' => $app_id,
'app_secret' => $psswd,
'default_graph_version' => 'v2.4',
]);
$request = $fb->request('POST', '/'.$group_id.'/feed',array('message'=>'This is a test message'));
// Send the request to Graph
try {
$response = $fb->getClient()->sendRequest($request);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
print_r($graphNode);
錯誤
致命錯誤:未捕獲的異常'Facebook \\ Exceptions \\ FacebookSDKException',並顯示消息'您必須提供訪問令牌'。
這是我發布到Facebook群組的代碼,它正在運行
<?php
// load autoload for composer packages
require('vendor/autoload.php');
// load the named consts file that contains all the sensitive info
require('includes/variables.php');
// load phpmailer settings
require('phpmailer.php');
$appsecret_proof = hash_hmac('sha256', token, app_secret);
// fb api
$fb = new Facebook\Facebook([
'app_id' => app_id,
'app_secret' => app_secret,
'appsecret_proof' => $appsecret_proof,
'default_graph_version' => 'v2.8'
]);
// make an array of the data that has to be posted
$dataToPost = [
'landingPage' => [
'link' => 'https://www.fiverr.com/s2/e6d69807e0',
'message' => 'Get a beautiful landing page or squeeze page for your business at $10 (exclusively on Fiverr).
The page will catch your audience\'s attention.
Get a working contact form with google reCaptcha on the page for free'
],
'PhpMySQLApp' => [
'link' => 'https://www.fiverr.com/s2/d8b0e8bcbb',
'message' => 'Get a Php and MySQL application done for your business.
I will build any Php or Mysql application that you need.'
]
];
// make an array of groups that need to be posted in
$groups = array('Entrepreneur' => '168892346490054', 'Internet Marketing' => '163901963701922', 'Affiliate Marketing and money making' => '184087555102491',
'Entrepreneurs Hut' => '366463540226995', 'Bangalore Start Up Connect' => '1546978348891191', 'Start Up Talky'=> '1628088717410164', 'Work from home' => '691810680861797',
'Affiliate Marketing' => '127166864003113');
// make array for storing the gig names and groups
$gigs = [];
$groupNames = [];
// post each data into each group
foreach ($groups as $groupName => $groupId) {
foreach ($dataToPost as $gigName => $gigLink) {
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->post('/' . $groupId . '/feed', $gigLink, token);
// push gig names and group names into the vars
array_push($gigs, $gigName);
array_push($groupNames, $groupName);
} 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 $gigName . ' posted into group <b>' . $groupName . '</b> with id: ' . $graphNode['id'] . '<br/>';
}
}
// set the mail subject
$mail->Subject = "Facebook Bot Posting";
// if successfully posted, then gigs and groupnames array
// will have items, then send an email informing it has been sent
if ( $gigs && $groupNames ) {
$gigs = array_unique($gigs, SORT_REGULAR);
$groupNames = array_unique($groupNames, SORT_REGULAR);
$msg = "Gigs: <br/>";
foreach ($gigs as $gig) {
$msg .= "<b>$gig</b>, ";
}
$msg .= "Posted into groups <br/>";
foreach ($groupNames as $groupName) {
$msg .= "<b>$groupName</b>, ";
}
$mail->Body = $msg . "<br/> Sent from post2.";
if ( $mail->send() ) {
echo "Mail sent <br/>";
} else {
echo "Mail not sent. Something wrong <br/>";
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.