$queries = array(
array('method' => 'GET', 'relative_url' => '/'.$user),
array('method' => 'GET', 'relative_url' => '/'.$user.'/home?limit=50'),
array('method' => 'GET', 'relative_url' => '/'.$user.'/friends'),
array('method' => 'GET', 'relative_url' => '/'.$user.'/photos?limit=6'),
);
// POST your queries to the batch endpoint on the graph.
try{
$batchResponse = $facebook->api('?batch='.json_encode($queries), 'POST');
}catch(Exception $o){
error_log($o);
}
//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_info = json_decode($batchResponse[0]['body'], TRUE);
$feed = json_decode($batchResponse[1]['body'], TRUE);
$friends_list = json_decode($batchResponse[2]['body'], TRUE);
我已将代码编辑为
$queries = array('method' => 'GET', 'relative_url' => '/'.$user);
try{
$batchResponse = $facebook->api('?batch='.json_encode($queries), 'POST');
}catch(Exception $o){
error_log($o);
}
$user_info = json_decode($batchResponse['body'], TRUE);
但是,当我回显$ user_info
时,它不再正常工作且没有值我做错了什么?
答案 0 :(得分:2)
您更改了嵌套数组结构。我想你需要:
$queries = array(
array('method' => 'GET', 'relative_url' => '/'.$user)
);
而不是
$queries = array('method' => 'GET', 'relative_url' => '/'.$user);
答案 1 :(得分:0)
最后一行:
array('method' => 'GET', 'relative_url' => '/'.$user.'/photos?limit=6'),
最后不应该有昏迷
array('method' => 'GET', 'relative_url' => '/'.$user.'/photos?limit=6')