1

my FQL returns illegal characters for UID. This is my FQL. select uid,books from user where uid in (select uid2 from friend where uid1=me()). I am using the PHP SDK and I am getting ids like 1.0000008018280E+14(Something with 'E'in between.). Around 400 of my total 600 contacts show UID like this.I tried pointing facebook.com/1.0000008018280E+14, which returns a 304 page not found error. The code I am using is

  $fql_query_url = 'https://graph.facebook.com/'.'fql?q=select+uid,books+from+user+where+uid+in(select+uid2+from+friend+where+uid1=me())'.'&access_token='.$_GET['access'];
   $fql_query_result = file_get_contents($fql_query_url);
   $fql_query_obj = json_decode($fql_query_result, true)

  // display results of fql query
echo '<pre>';
print_r($fql_query_obj);
echo '</pre>'; 
Niranjan
  • 172
  • 1
  • 5
  • 19
  • Please check it out on http://developers.facebook.com/tools/explorer/?fql=select%20uid%2Cbooks%20from%20user%20where%20uid%20in%20(select%20uid2%20from%20friend%20where%20uid1%3Dme()), see can reproduce the id 1.0000008018280E+14 or not. – 林果皞 Apr 23 '13 at 08:21
  • I checked it out, there is no problem there. I also found UID 100000105975568 is getting displayed like 1.0000010597557E+14. I think PHP is rounding off or something. Can someone explain this and suggest a possible work around? – Niranjan Apr 23 '13 at 23:13

1 Answers1

1

According to How to get around or make PHP json_decode not alter my very large integer values?, you can do on this way:

<?php
$fql_query_url = 'https://graph.facebook.com/'.'fql?q=select+uid,books+from+user+where+uid+in(select+uid2+from+friend+where+uid1=me())'.'&access_token='.$_GET['access'];
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_result = preg_replace('/:\s*(\-?\d+(\.\d+)?([e|E][\-|\+]\d+)?)/', ': "$1"', $fql_query_result);
$fql_query_obj = json_decode($fql_query_result, true);

echo '<pre>';
print_r($fql_query_obj);
echo '</pre>'; 
?>

or, as indicated on Handling big user IDs returned by FQL in PHP

<?php
$fql_query_url = 'https://graph.facebook.com/'.'fql?q=select+uid,books+from+user+where+uid+in(select+uid2+from+friend+where+uid1=me())'.'&access_token='.$_GET['access'];
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $fql_query_result), true);

echo '<pre>';
print_r($fql_query_obj);
echo '</pre>'; 
?>
Community
  • 1
  • 1
林果皞
  • 7,539
  • 3
  • 55
  • 70