I was using JQuery's $.getJSON to retrieve a list of tweets and for an unknown reason some of the tweet id(s) were being rounded
"id": 34903960418516968,
to "id": 34903960418516970,
So instead I tried using $.ajax with dataType: "text", and then did the conversion to JSON via parseJSON, JSON.parse and eval which did not work.
The only solution that I found was to make the datatype of the ID String instead of Number while the JSON source is still in text format. I surrounded the actual ID with double quotes " and I used the following regular expression to do that.
data = data.replace(/\"id\": (\d{15,}),/gi, "\"id\": \"$1\",");
ajax call
$.ajax({
async: true,
url: tweetsUrl,
dataType: "text",
success: getTweetsResult
});
the getTweetsResult
function getTweetsResult(data, textStatus, xhr){
//remove trailing ,
data = data.substring(0, data.lastIndexOf(",]")) + "]";
//convert tweet.id to string because the eval of JS is rounding up some of the number
data = data.replace(/\"id\": (\d{15,}),/g开发者_JS百科i, "\"id\": \"$1\",");
//console works with Chrome
// console.log(data);
var tweetList = $.parseJSON(data);
generateTweets("tweets", "tweetGrid", tweetList, 3, tweets);
applyRollOverGridItems();
}
I remember reading on the twitter blog that the twitter ID data type had changed and that developers had to update their code. If I remember correctly, they now send the ID as a string variable as well as a long (or float, not sure which) variable. Have a look at the response, and get the ID from the string variable. Should solve that issue.
EDIT: Found the URLS
http://groups.google.com/group/twitter-development-talk/browse_thread/thread/6a16efa375532182?pli=1
http://blog.programmableweb.com/2010/10/19/the-twitter-id-shuffle-text-vs-numbers/
Just open the .csv in TextEdit instead of in Excel. Excel will round numbers with more than 15 digits but TextEdit will leave the numbers as is
精彩评论