I'm making FQL calls using the following url and then making a curl call.
$url = 'https://api.facebook.com/method/fql.query?access_token='.$access_token.'&query='.rawurlencode($query).'&format=JSON';
and I then pass the returned data through a json_decode call
I've got this query:
SELECT name,page_id,page_url FROM page WHERE page_id IN (SELECT page_id FROM page_admin WHERE uid= $uid )
which returns a list of the names and pages for which the specified UID is an administrator.
On some PHP installs (and I've not been able to narrow it down) the page_id is turned from a long integer into a scientific notation - so 174311849258492 is returned as 1.7431184925849E 14 which of course breaks things.
As I can't reproduce this on my server I'm not sure where the conversion is happening. Digging around I've found a suggestion that doing this:
json_decode( preg_replace('/:(\d+,)/', ':"${1}",', $response ) );
will fix it
But why do some json_decodes cast into scientific notation for no apparent reason?
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: