如果特定数据丢失(例如当前城市),则捕获 FQL 数据中的错误
我一直在尝试使用 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 请求 失败的! HTTP/1.0 第 223 行 400 错误请求
我相信以下错误是因为用户没有在配置文件中提供当前位置。如果我添加数据,代码就可以正常工作。我如何捕获该错误?
I have been trying to retrieve the following data using the following code in 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>
Warning:
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]: failed to open stream: HTTP request
failed! HTTP/1.0 400 Bad Request in on line 223
I believe the following error is because the user has not provided current location in the profile. If I add the data the code works fine. How do I catch that error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“[function.file-get-contents]:无法打开流:HTTP 请求失败!第 223 行中的 HTTP/1.0 400 错误请求”
会告诉您,由于该函数失败,因此可以对结果进行逻辑测试,例如
"[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in on line 223"
Would tell you that as the function is failing, it can be tested logically for a result e.g.