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