如果特定数据丢失(例如当前城市),则捕获 FQL 数据中的错误

发布于 2024-12-13 06:20:46 字数 829 浏览 0 评论 0原文

我一直在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日裸衫吸 2024-12-20 06:20:46

“[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";

"[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.

$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";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文