【问题标题】:Illegal characters in Facebook FQLFacebook FQL 中的非法字符
【发布时间】:2013-04-23 02:58:31
【问题描述】:

我的 FQL 返回 UID 的非法字符。这是我的 FQL。 select uid,books from user where uid in (select uid2 from friend where uid1=me())。我正在使用 PHP SDK,我得到像1.0000008018280E+14(介于两者之间的东西。)。在我总共 600 个联系人中,大约有 400 个显示这样的 UID。我尝试指向 facebook.com/1.0000008018280E+14,它返回 304 未找到页面错误。我使用的代码是

  $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>'; 

【问题讨论】:

  • 请到developers.facebook.com/tools/explorer/…查看,看看能否重现id 1.0000008018280E+14。
  • 我查了一下,没有问题。我还发现 UID 100000105975568 显示为 1.0000010597557E+14。我认为 PHP 正在四舍五入之类的。有人可以解释一下并提出可能的解决方法吗?

标签: facebook-graph-api facebook-javascript-sdk facebook-fql illegalstateexception


【解决方案1】:

根据How to get around or make PHP json_decode not alter my very large integer values?,你可以这样做:

<?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>'; 
?>

或者,如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>'; 
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-03
    • 1970-01-01
    相关资源
    最近更新 更多