我一直在尝试使用php中的以下代码检索以下数据:
$fql_query='SELECT%20name,%20birthday_date,%20sex,%20current_location.name,%20email%20FROM%20user%20WHERE%20uid=me()';<br>
// Run fql query<br>
$fql_query_url = 'https://graph.facebook.com/'
. '/fql?q='.$fql_query
. '&' . $access_token;<br>
$fql_query_result = file_get_contents($fql_query_url);<br>
$fql_query_obj = json_decode($fql_query_result, true);<br>
警告: 的file_get_contents(https://graph.facebook.com//fql?q=SELECT%20name,%20birthday_date,%20sex,%20current_location.name,%20email%20FROM%20user%20WHERE%20uid=me()&安培; =的access_token ) [function.file-get-contents]:无法打开流:HTTP请求 失败!第223行的HTTP / 1.0 400错误请求
我认为以下错误是因为用户未在配置文件中提供当前位置。如果我添加数据代码工作正常。我该如何发现这个错误?
答案 0 :(得分:0)
“[function.file-get-contents]:无法打开流:HTTP请求失败!第223行HTTP / 1.0 400错误请求”
会告诉您,由于功能失败,可以逻辑测试结果,例如
$fql_query='SELECT%20name,%20birthday_date,%20sex,%20current_location.name,%20email%20FROM%20user%20WHERE%20uid=me()';
// Check FQL query
$fql_query_url = 'https://graph.facebook.com/'
. '/fql?q='.$fql_query
. '&' . $access_token;<br>
// First logically check the result, TRUE: Result is passed to $fql_query_result.
// FALSE: $flq_query_result = 0 or false.
$fql_query_result = file_get_contents($fql_query_url) ? file_get_contents($fql_query_url) : 0;
// Only json_decode the result if it was valid.
$fql_query_obj = (!$fql_query_result == 0) ? json_decode($fql_query_result, true) : "FQL was not a valid query";