[英]Correct Facebook Graph Api Video Insitghts Request PHP SDK
foreach( $videos_edge_array as $key => $video ) {
$requests[$key] = $fb->request('GET', '/'.$video['id'].'/video_insights', [ 'metrics' => 'total_video_views', 'period' => 'lifetime' ] );
}
try {
$batchResponse = $fb->sendBatchRequest($requests, $config['FACEBOOK']['ACCESS_TOKEN']);
} 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;
}
foreach ($batchResponse as $key => $response) {
if ($response->isError()) {
$error = $response->getThrownException();
echo $key . ' error: ' . $error->getMessage();
} else {
$videos[$key]['insights'] = $response->getGraphEdge()->asArray();
}
}
我認為代碼是自我描述的,但這只會給我空洞的響應...
$videos[$key]['insights']
應該有total_views指標,但是不知如何無法解決我的請求...我不知道該怎么做,我已經在此花費了很多時間。
我不太了解PHP。 但是我可以在這里加2美分。
在您的情況下,我可以想到以下問題:
如果所有者已授予user_videos
或user_posts
權限,則可以讀取用戶的視頻。
在video_insights文件不存在所謂的關鍵insights
。 因此,這行$videos[$key]['insights']
對我來說很簡單。
請參閱以下文檔: https : //developers.facebook.com/docs/graph-api/reference/video/ https://developers.facebook.com/docs/graph-api/reference/video/video_insights/
嘗試使用Facebook Graph API Explorer來測試URL的外觀。 如果您還沒有使用過,那么這是必須的。 請參閱這些屏幕截圖以供參考。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.