2011-04-24 82 views
2

* 更新 数据正在返回但未输出到浏览器。当我在下面的答案中使用urlencode建议后,我查看了源代码。**使用PHP提取FQL数据

用这个拉出我的头发。

基于以下链接:

facebook FQL overview

FQL Video table info

此代码应努力拉我所需要的表中的数据:

ini_set("display_errors","2"); 
ERROR_REPORTING(E_ALL); 

$contents = file_get_contents('https://api.facebook.com/method/fql.query?query=SELECT vid, owner, title, description, thumbnail_link, embed_html, updated_time, created_time FROM video WHERE owner= *******myID****'); 

echo $contents; 

但我正在以下错误:

Warning: file_get_contents(https://api.facebook.com/method/fql.query?query=SELECT vid, owner, title, description, thumbnail_link, embed_html, updated_time, created_time FROM video WHERE owner= ******myID*****) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /vservers/mywebsite/htdocs/test.php on line 5 

任何人都可以看到我做错了什么?

+0

如果您在尝试此浏览器,你会得到结果吗? – fingerman 2011-04-24 00:20:48

+0

以上错误是浏览器输出的内容。 – Denoteone 2011-04-24 00:26:23

+0

我的意思是网址:https://api.facebook.com/method/fql.query?query=SELECT vid,拥有者,标题,描述,缩略图链接,embed_html,updated_time,created_time从视频WHERE所有者= ***** ** myID **** – fingerman 2011-04-24 00:32:58

回答

5

尝试改变主线:

$enc = urlencode('SELECT vid, owner, title, description, thumbnail_link, embed_html, updated_time, created_time FROM video WHERE owner= *******myID****'); 
$contents = file_get_contents("https://api.facebook.com/method/fql.query?query=$enc"); 
+1

现在有一个不同的错误:警告:file_get_contents()[function.file-get-contents]:SSL:致命协议错误在第6行/vservers/lingua/htdocs/test.php – Denoteone 2011-04-24 00:15:45

1

您是否尝试过Facebook的PHP SDK:

https://github.com/facebook/php-sdk/

$result = $facebook->api(array(
    'query' => 'SELECT whatever FROM wherever WHERE something = something', 
    'method' => 'fql.query')); 

哦,看看这个:

You could try adding "limit 25" to the end of the query, or if you need to get as many status updates as possible, you can go up to 500. If a query would return more than 500 records and there is no limit explicitly stated in the query, Facebook returns an empty result: no errors, no nothing.

这可能不是你的错误,但要知道

+0

我看了在这个文档中(当然现在github不会出现)类需要一个应用程序密钥和密钥。这将涉及创建一个应用程序。我是否需要创建一个应用程序来提取我需要的数据? – Denoteone 2011-04-24 00:24:50

+0

处理我在那里,我认为它会工作,如果你把appid和appsecret设置为NULL .... – fingerman 2011-04-24 00:32:31

1

此错误是因为空间在URL请求而造成这一点很重要:

query=SELECT vid, owner 
------------^----^----- 

空间更改为%20 - 有用。 最简单的方法就是str_replace整个URL,或进行urlencode查询只(James C建议,上述),然后,如果需要的话,stripslashes你得到$内容

ini_set("display_errors","2"); 
ERROR_REPORTING(E_ALL); 

$url = 'https://api.facebook.com/method/fql.query?query=SELECT vid, owner, title, description, thumbnail_link, embed_html, updated_time, created_time FROM video WHERE owner= *******myID****'; 
$contents = file_get_contents(str_replace(" ", "%20", $url)); 
$contents = stripslashes($contents); 

echo $contents; 

// FETCHING RESULTS IT IN TO ARRAY: 
$array = json_decode($contents, true); 
print_r($array);