Correct Facebook Graph Api Video Insitghts Request PHP SDK

匿名 (未验证) 提交于 2019-12-03 01:09:02

问题:

 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.

回答1:

I dont understand PHP much. But I can add my 2 cents here.

In your scenario I can think of the following issues:

  • the URL that is being built is incorrect. Test this using GraphAPI Explorer.
  • the generated token doesn't have the required permissions to read the video content

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!