Facebook ID integers being returned oddly

岁酱吖の 提交于 2019-12-06 00:36:39

If you are using your own curl calls then you can simply append &format=JSON-STRINGS onto the end of the url which returns all items as strings.

As Danny pointed out its a 32/64 bit issue. FB assume that everything is 64 bit and pass back an integer for this value rather than a string.

So what you need to do is take the integers and convert them to strings BEFORE pulling them from the JSON array. Page IDs and Group IDs are passed as integers (Facebook user IDs are passed as strings)

The code to do this is:

    $response = curl_exec($ch);
    $err_no=curl_errno($ch);
    curl_close($ch);
    $response=preg_replace('/"gid":(\d+)/', '"gid":"$1"', $response );
    $response=json_decode( preg_replace('/"page_id":(\d+)/', '"page_id":"$1"', $response ) );
    if (isset($response->message)) { 
        throw new Exception ($response->message);
    }
    return( $response);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!