我有以下代码来获取fb页面列表
int readLine(FILE *infile, char **line_buffer) {
char * line = NULL;
size_t len = 0;
ssize_t read;
while ((read = getline(&line, &len, infile)) != -1) {
*line_buffer = line;
if(read == 0 || read == -1)
return -1;
return 1;
}
}
struct node *readStringList(FILE *infile) {
char* str_buffer;
while(readLine(infile, &str_buffer) == 1) {
// do something with str_buffer
// though remember to save it somewhere, you need to free() it later
}
[...]
$ pagedata 和 $ pages 为空,因此不会填充下拉列表。
在页面顶部的某处,我使用的是db.tests.aggregate({
$redact: {
$cond: {
if: {$eq: [ {$setIsSubset: [ '$a', [ "1", "2", "3" ] ]}]},
then: '$$KEEP',
else: '$$PRUNE'
}
}
})
,最后是 $graph_url_pages = "https://graph.facebook.com/me/accounts?access_token=".$_SESSION['token'];
$pagedata=file_get_contents($graph_url_pages);
echo "DATA : <br>";
print_r($pagedata);
$pages=json_decode($pagedata,true);
var_dump($pages);
$dropdown = "";
for($i=0;$i<count($pages->data);$i++)
{
if($me=="iamindex"){
$dropdown .= "<option value='".$pages->data[$i]->access_token."-".$pages->data[$i]->id."'>".$pages->data[$i]->name."</option>";
}elseif($me=="iammulti"){
$dropdown .= "<input type='checkbox' name='page' id='status' value='".$pages->data[$i]->access_token."-".$pages->data[$i]->id."'>".$pages->data[$i]->name."<br>";
}else{$dropdown.="<option value=''>No Category Selection</option>";}
}
并且需要它们。我不知道这是不是问题。
如果有人可以指出出了什么问题,那会很棒!如果需要更多代码,我可以提供。请注意我是业余程序员。自学成才。
答案 0 :(得分:1)
我建议使用cURL
$graph_url_pages = "https://graph.facebook.com/me/accounts?access_token=".$_SESSION['token'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $graph_url_pages);
if(curl_error($c))
{
echo 'error:' . curl_error($c);
//it will produce the error if any exists
}
$data = curl_exec($ch);
curl_close($ch);
print_r($data);