Pau*_*ega 8 php batch-file facebook-graph-api
使用Facebook提供的PHP库的2.1.2版本,针对Graph API设计我的第一个应用程序.试图最大限度地提高性能等,并希望将几个调用一起打成一个调用,但在文档中找不到任何内容......我确信我必须错过一些简单的东西,但我很难过.
我想将这些调用(仅作为示例)转换为单个批处理调用:
$me = $facebook->api('/me', $params);
$groups = $facebook->api('/me/groups', $params);
Run Code Online (Sandbox Code Playgroud)
buz*_*ord 50
只是新图形Batch API的更新:您也可以按如下方式执行:
// Save your method calls into an array
$queries = array(
array('method' => 'GET', 'relative_url' => '/me'),
array('method' => 'GET', 'relative_url' => '/me/groups')
);
// POST your queries to the batch endpoint on the graph.
$batchResponse = $facebook->api('?batch='.json_encode($queries), 'POST');
// Return values are indexed in order of the original array, content is in ['body'] as a JSON
// string. Decode for use as a PHP array.
$user_profile = json_decode($batchResponse[0]['body'], true);
$user_groups = json_decode($batchResponse[1]['body'], true);
Run Code Online (Sandbox Code Playgroud)
这应该够了吧.
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 from friend where uid1=' . $user_id . ')');
Run Code Online (Sandbox Code Playgroud)
如果您的请求不相互依赖,您可以使用fql.multiquery
| 归档时间: |
|
| 查看次数: |
11798 次 |
| 最近记录: |