twitter - Issue in getting the Time of creation of a tweet -
i'm using tweetsharp library display latest 5 tweets posted user. i've created app @ dev/twitter , got required tokens. want show time lapsed since tweet posted. "tweet.createddate" method tweetsharp library provides time 5-6 hrs before time of tweeting.
public dataset generatetweetdataset() { string time = ""; int hrs = 0, mins = 0; int days = 0; twitterservice service = new twitterservice(consumerkey, consumersecret); service.authenticatewith(accesstoken, accesstokensecret); listtweetsonusertimelineoptions tweetoptions = new listtweetsonusertimelineoptions(); tweetoptions.count = 5; tweetoptions.screenname = _twitter.screenname; var tweets = service.listtweetsonusertimeline(tweetoptions); datatable tweetstable = new datatable(); tweetstable.columns.add("text"); tweetstable.columns.add("datetime"); tweetstable.columns.add("id"); if (tweets != null) foreach (var tweet in tweets) { string username = tweet.user.screenname; string tweettext = tweet.text; datetime tweetdate = tweet.createddate; datetime currentdate = datetime.now; time = (currentdate - tweetdate).days.tostring(); timespan t1 = currentdate.subtract(tweetdate); mins = (int32)t1.totalminutes; hrs = (int32)t1.totalhours; days = (int32)t1.totaldays; if (mins < 60) { time = mins + " mins ago"; } else if (mins > 60 && hrs <= 24) { time = hrs + " hours ago"; } else if (hrs > 24 && days < 365) { time = days + " days ago"; } else if (days > 365) { time = "over year ago"; } long id = tweet.id; tweetstable.rows.add(tweettext, time, id); } dataset ds = new dataset(); ds.tables.add(tweetstable); return ds; }
can please point i'm going wrong or how fix issue. if not then, there better/simpler way tweets? sample code without using api library? appreciated.
literal litauthor = (literal)e.item.findcontrol("litauthor"); literal littime = (literal)e.item.findcontrol("littime"); hyperlink btntwitter = (hyperlink)e.item.findcontrol("btntwitter"); twitterstatus twitterstatus = (twitterstatus)e.item.dataitem; if (litauthor != null) { if (twitterstatus != null) { timespan diff = datetime.now - twitterstatus.createddate; if (diff.days > 0) { littime.text = twitterstatus.createddate.tostring("dd mmm yyyy"); } else if (diff.hours < 24) { littime.text = diff.hours.tostring() + "h"; } else { littime.text = diff.minutes.tostring() + "m"; } litauthor.text = twitterstatus.author.screenname; btntwitter.text = twitterstatus.text; btntwitter.navigateurl = "http://twitter.com/" + twitterstatus.user.screenname + "/statuses/" + twitterstatus.idstr; } }
Comments
Post a Comment