我编写了以下代码来了解fql multiquery的工作原理:
include_once "fbmain.php";
try{
$your_id=xxxxxxxx;
$fql= '{
"friends":"SELECT uid2 FROM friend WHERE uid1='.$your_uid.',"
"friendinfo":"SELECT * FROM standard_user_info WHERE uid IN (SELECT uid2
FROM #friends)"
}';
$res = $facebook->api_client->fql_multiquery($fql);
}
catch(Exception $o){
d($o); // d() is function to print
}
但输出显示错误
在第9行的非对象上调用成员函数fql_multiquery()
我也尝试过其他查询而不是这两个,但问题仍然存在。我正在使用php sdk 3.0。
帮忙。
答案 0 :(得分:0)
我不使用Multi Query,因为fql已经移动到图形api。相反,我使用批量请求。 这是一个/ feed请求的示例,前10个结果的注释和来自前10个帖子的固定链接的fql multi。我确信这对你所需要的东西来说有点过分了,但这是我用混合图形和fql以及使用名称功能的最好例子,这似乎是你需要携带的朋友。
https://developers.facebook.com/docs/reference/api/batch/
<?php
if($type=="home"){
$relURL = '/'.$pageid.'/'.$type.'?'.$access_token.'%26limit='.$limit.'%26return_ssl_resources=1%26fields=id,from,name,message,likes,comments,link,picture,caption,story,source,created_time,type,actions,application,object_id,description%26since='.$since.'%26until='.$until.'%26offset='.$offset.'';
}else{
$relURL = '/'.$pageid.'/'.$type.'?'.$app_access_token.'%26limit='.$limit.'%26return_ssl_resources=1%26fields=id,from,name,message,likes,comments,link,picture,caption,story,source,created_time,type,actions,application,object_id,description%26since='.$since.'%26until='.$until.'%26offset='.$offset.'';
}
$queryProfile = array(
array('method' => 'GET', 'relative_url' => '/'.$pageid.'?fields=id,name,link,picture%26'.$app_access_token.''),
array('method' => 'GET', 'relative_url' => ''.$relURL.'', 'name' => 'comments', 'omit_response_on_success' => false),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.0.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.1.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.2.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.3.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.4.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.5.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.6.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.7.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.8.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/{result=comments:$.data.9.id}/comments?fields=id,from,message,created_time%26limit=3%26offset=0'),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.0.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.1.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.2.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.3.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.4.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.5.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.6.id}\''),
array('method' => 'GET', 'relative_url' => '/fql?q=SELECT+permalink+FROM+stream+WHERE+source_id=\''.$pageid.'\'+AND+post_id=\'{result=comments:$.data.7.id}\''),
//array('method' => 'GET', 'relative_url' => '/'.$pageInfo[id].'/photos?fields=id,name%26limit=9')
);
$batchResponse = $facebook->api('?batch='.json_encode($queryProfile), 'POST');
$pageInfo = json_decode($batchResponse[0]['body'], true);
$pageType = $pageInfo[type];
$pageLink = $pageInfo[link];
$thispageid = $pageInfo[id];
$MEcomments = json_decode($batchResponse[1]['body'], true);
?>
答案 1 :(得分:0)
看起来很像
的实例化问题$facebook->api_client
值得注意的是,在[standard_user_info]中,[uid]列的类型为 string ,因此您可能还需要添加引号。
https://developers.facebook.com/docs/reference/fql/standard_user_info/
根据FB文档,FQL多查询应该比后续批处理调用更快。 https://developers.facebook.com/docs/reference/fql/