如何检索位于特定位置并被用户朋友点赞的 Facebook 页面(地点)的 ID?
How to retrieve the IDs of Facebook pages (places) located in a specific location and liked by a user's friends?
我知道一种解决方案是使用 Facebook Graph API 检索位于特定位置的地点的 ID,检索我朋友喜欢的所有 Facebook 页面的 ID,然后仅选择我的朋友喜欢的位置中的页面 ID(使用 "social context" 让我知道有多少朋友喜欢一个页面)。但这对我来说听起来不是最好的解决方案(它代表大量数据)。
另一种解决方案可能是使用 JSONPath
表达式格式 (https://developers.facebook.com/docs/graph-api/making-multiple-requests/) 暗示请求中操作之间的依赖关系,但如文档 "for security reasons filter and script JSONPath constructs are not allowed in the JSONPath expression" 中所述,这显着限制了实用性这个策略。
所以我尝试使用批处理请求:
curl \
-F 'access_token=...' \
-F 'batch=[{"method":"GET", "name":"likes-ids", "relative_url":"me/friends?fields=likes{id}"}, {"method":"GET", "relative_url":"search?type=place¢er=48.85,2.35&distance=1000&ids={result=likes-ids:$.data.*.likes.data.*.id}"}]'
每个批请求中有 2 个问题:
- 奇怪的是,"me/friends?fields=likes{id}" 让我喜欢
我的一些朋友(我认为有可能得到所有喜欢的人
我所有的朋友因为 friends_likes 已被弃用,请纠正我
我错了)
- 连用户朋友的点赞我都做到了
检索,我没有从第二批请求中得到任何东西。
注意:用户的朋友不需要登录我的应用程序(这意味着我没有他们的 user_likes
权限)。
如果有人能提供一些意见或想法,我将不胜感激。
您需要好友授予user_likes
。您可能正在使用 Graph API Explorer,因此您的朋友可能已经进行了测试并授予了 user_likes
权限(因此您看到了一些而不是全部)
A user access token with user_likes permission is required to see all pages liked by that person.
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/likes
注意它没有说朋友。
对于第二部分,您确定从批处理的第一部分返回的 ID 包含地点 ID 吗?对于每个朋友对象,只返回 25 个赞,你不能保证你得到的赞是 place 类型的页面。
另外 search?type=place¢er=48.85,2.35&distance=1000&ids=
,我不认为这符合您的预期。 ids
似乎覆盖了类型、中心和距离。
例如search?type=place¢er=48.85,2.35&distance=1000&ids=375093055847509
与
相同
search?ids=375093055847509
这里似乎是一个错误或预期的行为,随着返回的 id 覆盖所有其他参数。
总的来说不,这个批处理调用会起作用,你返回的结果不符合你想要的结果。
所以唯一的方法确实是您最初的计划但是无论如何查询只对使用您的应用程序的朋友有效。
https://developers.facebook.com/docs/graph-api/reference/v2.2/page.context/friends_who_like
Only friends who use the requesting app will be returned.
我知道一种解决方案是使用 Facebook Graph API 检索位于特定位置的地点的 ID,检索我朋友喜欢的所有 Facebook 页面的 ID,然后仅选择我的朋友喜欢的位置中的页面 ID(使用 "social context" 让我知道有多少朋友喜欢一个页面)。但这对我来说听起来不是最好的解决方案(它代表大量数据)。
另一种解决方案可能是使用 JSONPath
表达式格式 (https://developers.facebook.com/docs/graph-api/making-multiple-requests/) 暗示请求中操作之间的依赖关系,但如文档 "for security reasons filter and script JSONPath constructs are not allowed in the JSONPath expression" 中所述,这显着限制了实用性这个策略。
所以我尝试使用批处理请求:
curl \
-F 'access_token=...' \
-F 'batch=[{"method":"GET", "name":"likes-ids", "relative_url":"me/friends?fields=likes{id}"}, {"method":"GET", "relative_url":"search?type=place¢er=48.85,2.35&distance=1000&ids={result=likes-ids:$.data.*.likes.data.*.id}"}]'
每个批请求中有 2 个问题:
- 奇怪的是,"me/friends?fields=likes{id}" 让我喜欢 我的一些朋友(我认为有可能得到所有喜欢的人 我所有的朋友因为 friends_likes 已被弃用,请纠正我 我错了)
- 连用户朋友的点赞我都做到了 检索,我没有从第二批请求中得到任何东西。
注意:用户的朋友不需要登录我的应用程序(这意味着我没有他们的 user_likes
权限)。
如果有人能提供一些意见或想法,我将不胜感激。
您需要好友授予user_likes
。您可能正在使用 Graph API Explorer,因此您的朋友可能已经进行了测试并授予了 user_likes
权限(因此您看到了一些而不是全部)
A user access token with user_likes permission is required to see all pages liked by that person.
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/likes
注意它没有说朋友。
对于第二部分,您确定从批处理的第一部分返回的 ID 包含地点 ID 吗?对于每个朋友对象,只返回 25 个赞,你不能保证你得到的赞是 place 类型的页面。
另外 search?type=place¢er=48.85,2.35&distance=1000&ids=
,我不认为这符合您的预期。 ids
似乎覆盖了类型、中心和距离。
例如search?type=place¢er=48.85,2.35&distance=1000&ids=375093055847509
与
相同search?ids=375093055847509
这里似乎是一个错误或预期的行为,随着返回的 id 覆盖所有其他参数。
总的来说不,这个批处理调用会起作用,你返回的结果不符合你想要的结果。
所以唯一的方法确实是您最初的计划但是无论如何查询只对使用您的应用程序的朋友有效。
https://developers.facebook.com/docs/graph-api/reference/v2.2/page.context/friends_who_like
Only friends who use the requesting app will be returned.