Reputation: 271
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();
}
}
I think code is self descriptive, but this returns me just empty response...
$videos[$key]['insights']
Should have total_views metrics in it, but somehow doesnt resolve from my request... I have no Idea what to do, I already spend a lot of time on this.
Upvotes: 0
Views: 340
Reputation: 2467
I dont understand PHP much. But I can add my 2 cents here.
In your scenario I can think of the following issues:
A user's videos can be read if the owner has granted the user_videos
or user_posts
permission.
In the video_insights documentation there is no key called insights
. So this line $videos[$key]['insights']
seems dicey to me.
Refer the following documentation: https://developers.facebook.com/docs/graph-api/reference/video/ https://developers.facebook.com/docs/graph-api/reference/video/video_insights/
Try using the Facebook Graph API Explorer to test how the URL should look like. If you haven't used it, then it is a must. See these screenshots for reference.
Upvotes: 1