tags:

views:

587

answers:

2

Hi experts,

as you know Twitter has posted a new cursor based pagination for some API methods.

Currently, I'm facing a problem when encoding the json object because the cursor itself is actually a 64-bit numbers and not supported for json encoding in PHP.

next_cursor 1299072354878293926

Any solution for this? I can't believe why didn't Twitter just return string for it...hmmp

thx

+1  A: 

PHP 5.2+ should convert 64-bit numbers to floats, which is better than previous versions of PHP (which would just convert it to the maximum 32-bit value). Best bet is to move to a 64-bit version of PHP, but updating to PHP 5.2+ will at least get you up and running.

ceejayoz
it does covert to floats..but i need the number to allow me navigate through the data...i"m using the PHP 5.2+...Converting to 64-bit seems impossible to me, though it will definitely solve the issue...
andy
A: 

If you are stuck with 32 bit system, you could convert the cursor to string using regex and then use it for further requests.

Here's PHP function that I am using to achieve this:

function jsonIntToStr($json){
$pattern = "/\"next_cursor\":([0-9]+),/";
$replace = "\"next_cursor\":\"$1\",";
$new_json = preg_replace($pattern, $replace, $json);
$pattern = "/\"previous_cursor\":([0-9]+),/";
$replace = "\"previous_cursor\":\"$1\",";
$new_json = preg_replace($pattern, $replace, $new_json); 
return $new_json; 
}

and you could use it like:

$json_result = json_decode(jsonIntToStr($twitter_response));

Got it from twitter development talk google group.

vsr

related questions