之前一直用facebook 2.6的api,现在想升级到2.8.但是2.8的api做了一些调整。有些api的参数已经不一样了。
各个版本的api的停用时间表见:
https://developers.facebook.com/docs/apps/changelog
版本 路径 推出日期 停用日期
v2.8
/v2.8/{object}
2016 年 10 月 5 日
至少到 2018 年 10 月
v2.7
/v2.7/{object}
2016 年 7 月 13 日
2018 年 10 月 5 日
v2.6
/v2.6/{object}
2016 年 4 月 12 日
2018 年 7 月 13 日
v2.5
/v2.5/{object}
2015 年 10 月 7 日
2018 年 4 月 12 日
v2.4
/v2.4/{object}
2015 年 7 月 8 日
2017 年 10 月 7 日
v2.3
/v2.3/{object}
2015 年 3 月 25 日
2017 年 7 月 8 日
v2.2
/v2.2/{object}
2014 年 10 月 30 日
2017 年 3 月 25 日
v2.1
/v2.1/{object}
2014 年 8 月 7 日
2016 年 10 月 30 日
v2.0
/v2.0/{object}
2014 年 4 月 30 日
2016 年 8 月 7 日起停用
v1.0
/{object}
2010 年 4 月 21 日
2015 年 4 月 30 日起停用
例如之前获取post insight的api
https://graph.facebook.com/v2.6/page_id/insights?debug=all&access_token=xxx&format=json&method=get
是可以获取到post insight的所有数据的。而改成2.8则会报错:
{
"error": {
"message": "Invalid query",
"type": "OAuthException",
"code": 3001,
"error_subcode": 1504028,
"is_transient": false,
"error_user_title": "No Metric Specified",
"error_user_msg": "No metric was specified to be fetched. Please specify one or more metrics to be fetched and try again.",
"fbtrace_id": "AnenpDXtC4N"
},
"__debug__": {
}
}
必须传递metric参数。
我们可以在图谱explore中试下
https://developers.facebook.com/tools/explorer/?method=GET&path=xxx%2Finsights%2F%3Fmethod%3Dget%26format%3Djson%26access_token%xxx%26debug%3Dall&version=v2.8
metric list:
https://developers.facebook.com/docs/graph-api/reference/v2.8/insights#metrics
例如我要获取post_impressions_organic 和post_reactions_by_type_total。则url加上
https://graph.facebook.com/v2.8/page_id/insights/["post_impressions_organic","post_reactions_by_type_total"]?debug=all&format=json&method=get
这样就能返回数据了..
需要注意的是,since和until的时间戳应该用UTC时间。建议时间差异最大为 6 个月。
(
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.1
)
{
"data": [
{
"name": "post_impressions_by_paid_non_paid",
"period": "lifetime",
"values": [
{
"value": {
"total": 123609,
"unpaid": 123609,
"paid": 0
}
}
],
"title": "Lifetime Post impressions by paid and non-paid",
"description": "Lifetime: The number of impressions of your Page post broken down by paid and non-paid. (Total Count)",
"id": "xxx/insights/post_impressions_by_paid_non_paid/lifetime"
},
{
"name": "post_story_adds_by_action_type",
"period": "lifetime",
"values": [
{
"value": {
"like": 822,
"comment": 66,
"share": 39
}
}
],
"title": "Lifetime Post Stories by action type",
"description": "Lifetime: The number of stories created about your Page post, by action type. (Total Count)",
"id": "xxx/insights/post_story_adds_by_action_type/lifetime"
},
{
"name": "post_video_views",
"period": "day",
"values": [
{
"value": 0,
"end_time": "2017-02-11T08:00:00+0000"
},
{
"value": 0,
"end_time": "2017-02-12T08:00:00+0000"
},
{
"value": 0,
"end_time": "2017-02-13T08:00:00+0000"
}
],
"title": "Daily Total Video Views",
"description": "Daily: Total number of times your video was viewed for more than 3 seconds. (Total Count)",
"id": "xxx/insights/post_video_views/day"
},
{
"name": "post_video_views",
"period": "lifetime",
"values": [
{
"value": 36
}
],
"title": "Lifetime Total Video Views",
"description": "Lifetime: Total number of times your video was viewed for more than 3 seconds. (Total Count)",
"id": "xxx/insights/post_video_views/lifetime"
},
{
"name": "post_consumptions_by_type",
"period": "lifetime",
"values": [
{
"value": {
"other clicks": 6326,
"link clicks": 8833
}
}
],
"title": "Lifetime Post Consumptions by type",
"description": "Lifetime: The number of clicks anywhere in your post, by type. (Total Count)",
"id": "xxx/insights/post_consumptions_by_type/lifetime"
},
{
"name": "post_reactions_by_type_total",
"period": "lifetime",
"values": [
{
"value": {
"like": 770,
"love": 21,
"wow": 0,
"haha": 29,
"sorry": 1,
"anger": 1
}
}
],
"title": "Lifetime Total post Reactions by Type.",
"description": "Lifetime: Total post reactions by type.",
"id": "xxx/insights/post_reactions_by_type_total/lifetime"
}
],
"paging": {
"previous": "https://graph.facebook.com/v2.8/xxx/insights/['post_impressions_by_paid_non_paid','post_story_adds_by_action_type','post_video_views','post_consumptions_by_type','post_reactions_by_type_total']/?access_token=xxx&debug=all&format=json&method=get&pretty=0&suppress_http_code=1&since=1486458350&until=1486717550",
"next": "https://graph.facebook.com/v2.8/xxx/insights/['post_impressions_by_paid_non_paid','post_story_adds_by_action_type','post_video_views','post_consumptions_by_type','post_reactions_by_type_total']/?access_token=xxx&debug=all&format=json&method=get&pretty=0&suppress_http_code=1&since=1486976750&until=1487235950"
},
"__debug__": {
}
}