PHP 中 Facebook ID 值的格式不正确
我使用以下代码来检索用户的好友:
$fql_query_url = 'https://graph.facebook.com/fql?q=SELECT+uid,+name,+pic_square+FROM+user+WHERE+uid+IN+(SELECT+uid2+FROM+friend+WHERE+uid1+=+me())+order+by+name&access_token=' . $_SESSION['token'];
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
它工作得很好,只是对于长度超过 11 个数字的任何 Facebook ID,它们会呈现为 1.xxxxxxxxxxxxxE+14 而不是 1xxxxxxxxxxxxxxx。 (例如:100000776800425 变为 1.0000077680042E+14)。除了最后一位数字丢失之外,这不会是一个问题。
令人烦恼的是,如果我在地址栏中插入查询 URL,ID 不会改变。如果我查询“SELECT uid2 FROMfriend WHERE uid1 = me()”,ID 也不会更改。
造成这种情况的原因是什么以及如何解决它?谢谢。
编辑:
我至少设法确定值在 json_decode 期间发生了变化,但除此之外,什么都没有。
编辑2:
添加 ini_set(' precision', 20) 解决了它。
I'm using the following code to retrieve a user's friends:
$fql_query_url = 'https://graph.facebook.com/fql?q=SELECT+uid,+name,+pic_square+FROM+user+WHERE+uid+IN+(SELECT+uid2+FROM+friend+WHERE+uid1+=+me())+order+by+name&access_token=' . $_SESSION['token'];
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
It works just fine except that for any Facebook IDs that are more than 11 numbers long, they get rendered as 1.xxxxxxxxxxxxxE+14 instead of 1xxxxxxxxxxxxxx. (ex: 100000776800425 instead becomes 1.0000077680042E+14). This wouldn't be a problem except that the last digit gets lost.
Annoyingly, if I plug in the query URL in the address bar, the IDs don't get changed. The IDs don't get changed either if I query for "SELECT uid2 FROM friend WHERE uid1 = me()".
What is causing this and how do I get around it? Thanks.
Edit:
I've at least managed to determine that the values get changed during json_decode but other than that, nothing.
Edit 2:
Adding ini_set('precision', 20) solved it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
php 设置导致该值转换为 int,这缺乏正确显示较长 Facebook ID 所需的长度。在脚本开头添加 ini_set(' precision', 20) 将精度提高到 20 位。
php settings cause the value to be converted to an int, which lacks the necessary length to properly display longer Facebook IDs. Adding ini_set('precision', 20) at the start of the script increased the precision to 20 digits.