我对处理Facebook Graph API有一点经验。我需要获得视频的每日观看次数,而不是一生的观看次数。
FB API文档未将其显示为选项(生存期-仅周期参数) https://developers.facebook.com/docs/graph-api/reference/video/video_insights/
但是,我在SO上看到了另一篇文章,回答了这个问题,但是由于某些原因,它对我不起作用 (Getting a video views with Facebook API)。
这是我成功的API调用,可以按预期返回生命周期统计信息:
/{video_id}/video_insights/total_video_views/lifetime
这就是我应该做的:
/{video_id}/video_insights/total_video_views/day
...但是出现此错误:
{
"error": {
"message": "(#100) Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_data": "Daily query is not supported for metric (total_video_views)"
}
}
然后,按照SO帖子的建议,我尝试了不同时期的参数:
/{video_id}/video_insights/total_video_views/month
...并且得到了:
{
"error": {
"message": "(#100) Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_data": "Period should be either lifetime or day."
}
}
...表示 day 应该是可以接受的参数,就像 lifetime
最终,只是为了好玩,我以为我会传递“错误的”参数- Day :
/{video_id}/video_insights/total_video_views/Day
...并且得到了:
{
"error": {
"message": "(#100) For field 'video_insights': period must be one of the following values: day, week, days_28, month, lifetime",
"type": "OAuthException",
"code": 100
}
}
这表明所有这些值都很好(天,周, days_28 ,月,< strong> lifetime ),但它们不起作用。
我真的很困惑。我每天看到FB网页/见解的视频观看次数细分,并认为应该可以通过API进行同样的操作。
我在做什么错了?
答案 0 :(得分:1)
发布您后不久,我遇到了同样的问题。我所有的测试和研究都使我相信Facebook取消了检索除终生之外的任何内容的功能。在阅读了最后几个版本的所有变更日志之后,我看不到Facebook记录了任何有关变更的证据。这显然非常令人失望。
API响应清楚地表明“天”应该是有效期限,这使我认为它已被匆匆删除。
不幸的是,我看不到可靠的解决方法。通过每24小时检索一次生命并计算两者之间的差值,人们也许可以实现每天的近似值。尽管这只是一个近似值,因为在给定的时间段内可能存在数据协调问题。
很遗憾,此问题没有得到任何关注,因为它是Facebook Video Insights API的核心。
答案 1 :(得分:0)
这是我的解决方案(通过FB支持运行后)
基本上,
1)我得到所有帖子的列表:
fields='object_id,type'
url="https://graph.facebook.com/v3.2/{}?access_token={}&fields={}&limit={}".format(resource_id,access_token,fields,limit)
while url:
rec=requests.request(method="GET",url=url)
content = json.loads(rec.content)
if "next" in content["paging"]:
url=content["paging"]["next"]
else:
url=False
break
2),然后遍历每个视频(用视频过滤视频),并检索包含该视频而不是 帖子 的数据>视频 本身(事实证明,每天的分组不再可行)
insights=[]
video_post_id=page_id+"_"+video_id
metric="post_video_views"
url_insight=f"https://graph.facebook.com/v3.2/{video_post_id}/insights?metric={metric}&since={since}&until={until}&pretty=0&access_token={access_token}"
while url_insight:
rec=requests.request(method="GET",url=url_insight)
insight = json.loads(rec.content)
if "next" in insight["paging"]:
url_insight=insight["paging"]["next"]
else:
url_insight=False
break
这对我有用