使用 Facebook Graph API & 进行批量调用PHP

2021-12-20 00:00:00 batch-file php facebook-graph-api

使用 Facebook 提供的 PHP 库的 2.1.2 版,针对 Graph API 设计我的第一个应用程序.试图最大限度地提高性能等开箱即用,并希望将几个调用一起批处理为一个调用,但在文档中找不到任何内容......我确定我一定遗漏了一些简单的东西,但我很难过.

我想将这些调用(只是一个示例)转换为单个批处理调用:

$me = $facebook->api('/me', $params);$groups = $facebook->api('/me/groups', $params);

解决方案

Facebook 推荐使用 FQL 为此;http://developers.facebook.com/docs/guides/performance通过在(嵌套)查询中组合您的请求.

他们自己的例子:

$friends_locations = $facebook->api_client->fql_query('SELECT hometown_location from user where uid in ' .'(SELECT uid2 fromfriend where uid1=' . $user_id . ')');

如果您的请求不相互依赖,您可以使用 fql.multiquery

Designing my first app against the Graph API, using version 2.1.2 of the Facebook supplied PHP library. Trying to maximize performance, etc out of the box and want to batch a few calls together into one call, but can't find anything in the documentation... I am sure I must be missing something simple, but am stumped.

I'd like to turn these calls (just an example) into a single batched call:

$me     = $facebook->api('/me', $params);
$groups = $facebook->api('/me/groups', $params);

解决方案

Facebook recommends using FQL for this; http://developers.facebook.com/docs/guides/performance by combining your requests in a (nested) query.

Their own example:

$friends_locations = $facebook->api_client->fql_query(
    'SELECT hometown_location from user where uid in ' .
    '(SELECT uid2 from friend where uid1=' . $user_id . ')');

If your requests aren't dependant on eachother you can use fql.multiquery

相关文章