正确的Facebook图表Api视频Insitghts请求PHP SDK [英] Correct Facebook Graph Api Video Insitghts Request PHP SDK
问题描述
$ requests [$ key] = $ fb->请求('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){
//当Graph返回错误
echo'Graph返回错误:'。 $ E->的getMessage();
退出;
} catch(Facebook\Exceptions\FacebookSDKException $ e){
//验证失败或其他本地问题时
echo'Facebook SDK返回错误:'。 $ E->的getMessage();
退出;
}
foreach($ batchResponse as $ key => $ response){
if($ response-> isError()){
$ error = $响应 - > getThrownException();
echo $ key。 '错误:'。 $无错误>的getMessage();
} else {
$ videos [$ key] ['insights'] = $ response-> getGraphEdge() - > asArray();
}
}
我认为代码是自我描述的,但这会让我回来只是空的回复...
$ videos [$ key] ['insights']
应该有total_views指标,但不知何故不能从我的请求中解决...我没有想法要做什么,我已经花了很多的时间。
我不懂PHP。但我可以在这里加上我的2美分
在您的场景中,我可以想到以下问题:
- URL正在建造的是不正确的。使用GraphAPI Explorer进行测试。
- 生成的令牌没有读取视频内容所需的权限
A如果所有者已经授予 user_videos
或 user_posts
权限,则可以读取用户的视频。
在video_insights文档中没有名为见解
的键。所以这一行 $ videos [$ key] ['insights']
对我来说似乎很狡猾。
请参阅以下文档:
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.
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图表Api视频Insitghts请求PHP SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!