c# - how to get all tweets on hashtag using Tweetsharp -
how can tweets on behalf of specific hashtag/keyword , display on view page? solution found returns null exception.
public actionresult tweetview(string txttwittername) { //twitterservice("consumer key", "consumer secret"); var service = new twitterservice("", ""); //authenticatewith("access token", "accesstokensecret"); service.authenticatewith("", ""); twittersearchresult tweets = service.search(new searchoptions { q = txttwittername, sinceid=29999 }); ienumerable<twitterstatus> status = tweets.statuses; viewbag.tweets = tweets; return view(); }
view :
ienumerable<twitterstatus> tweets = viewbag.tweets ienumerable<twitterstatus>; foreach (var tweet in tweets) { <div class="tweet"> <div class="picture"> <img src="@tweet.user.profileimageurl" alt="@tweet.user.screenname" title="@tweet.user.screenname" /> </div> <div class="info"> <span>@tweet.user.name, @tweet.user.description - @tweet.user.location </span> <br /> <a href="https://twitter.com/statuses/@tweet.id" class="text"> @tweet.text </a> <div class="action"> @tweet.createddate.addhours(3).tostring("d/m/yyyy hh:mm:ss") </div> </div> <div class="clear"> </div> </div> }
for null value, in view :
ienumerable<twitterstatus> status = viewbag.tweets ienumerable<twitterstatus>; if(status != null ) { foreach (var tweet in status) { <div class="tweet"> <div class="picture"> <img src="@tweet.user.profileimageurl" alt="@tweet.user.screenname" title="@tweet.user.screenname" /> </div> <div class="info"> <span>@tweet.user.name, @tweet.user.description - @tweet.user.location </span> <br /> <a href="https://twitter.com/statuses/@tweet.id" class="text"> @tweet.text </a> <div class="action"> @tweet.createddate.addhours(3).tostring("d/m/yyyy hh:mm:ss") </div> </div> <div class="clear"> </div> </div> } }
and controller, modify last code :
viewbag.tweets = status;
i hope post help, thx :)
Comments
Post a Comment