我終於達到了我自己的問題的答案不知何故。謝謝大家的關注和回答。但是請允許我張貼我自己的答案,因爲我終於可以弄明白了,希望它可以幫助那些像我這樣的Graph API新手。
我弄明白由Facebook的下載API文檔閱讀降價促銷文件夾,如下:
C:\ Facebook的PHP-SDK-v4-5.0.0 \文檔
下面是我的要求的代碼片段:
<?php
require_once('Facebook/autoload.php');
use Facebook\Facebook;
use Facebook\FacebookApp;
use Facebook\FacebookRequest;
$app_id = "appid";
$secret = "secret";
$access_token = "accesstoken";
$fb = new Facebook([
'app_id' => $app_id,
'app_secret' => $secret,
'default_graph_version' => 'v2.5',
'default_access_token' => $access_token,
]);
// Create request
// $fbApp = new FacebookApp($app_id, $secret);
// $request = new FacebookRequest($fbApp, $access_token, 'GET', '/GROUPID/posts');
// Alternative request
// $request = $fb->request('GET', '/GROUPID/posts');
// Send the request to Graph
try {
// $response = $fb->getClient()->sendRequest($request);
$response = $fb->get('/GROUPID/posts');
} 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;
}
echo "<pre>";
// print_r($response->getDecodedBody());
$decodedBody = $response->getDecodedBody();
$data = $decodedBody['data'];
foreach ($data as $key => $value) {
try {
$request = $fb->request('GET', '/'.$value['id'].'?fields=id,message,picture,object_id,attachments');
$post = $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;
}
print_r($post);
}
圖形API資源管理器結果
[頁饋送(https://developers.facebook.com/docs/graph-api/reference/v2.5/page/feed)和[組飼料](https://developers.facebook.com/docs/graph-api/reference/v2.5/group/feed)。您需要更改'READING'選項卡以查看PHP示例:P。但它是5.0,請閱讀(Facebook的PHP SDK更新日誌)[https://www.sammyk.me/upgrading-the-facebook-php-sdk-from-v4-to-v5]看到兩個版本的不同。 – Vuong