Eric lippert - Amazon Web Services
Eric lippert - Amazon Web Services
Eric lippert - Amazon Web Services
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
credentials.ConsumerKey = ConfigurationManager.<br />
AppSettings[“twitterConsumerKey”];<br />
credentials.ConsumerSecret = ConfigurationManager.<br />
AppSettings[“twitterConsumerSecret”];<br />
}<br />
auth = new MvcAuthorizer<br />
{<br />
Credentials = credentials<br />
};<br />
auth.CompleteAuthorization(Request.Url);<br />
if (!auth.IsAuthorized)<br />
{<br />
Uri specialUri = new Uri(Request.Url.ToString());<br />
return auth.BeginAuthorization(specialUri);<br />
}<br />
IEnumerable friendTweets =<br />
new List();<br />
if (string.IsNullOrEmpty(screenName))<br />
{<br />
return View(friendTweets);<br />
}<br />
twitterCtx = new TwitterContext(auth);<br />
IEnumerable friendTweets =<br />
(from tweet in twitterCtx.Status<br />
where tweet.Type == StatusType.User &&<br />
tweet.ScreenName == screenName &&<br />
tweet.IncludeEntities == true<br />
select new TweetViewModel<br />
{<br />
ImageUrl = tweet.User.ProfileImageUrl,<br />
ScreenName = tweet.User.Identifier.ScreenName,<br />
MediaUrl = GetTweetMediaUrl(tweet),<br />
Tweet = tweet.Text<br />
})<br />
.ToList();<br />
return View(friendTweets);<br />
}<br />
{<br />
if (status.Entities != null &&<br />
status.Entities.MediaMentions.Count > 0)<br />
{<br />
return status.Entities.MediaMentions[0].MediaUrlHttps;<br />
}<br />
return “”;<br />
}<br />
This wraps up the Controller and now we can finally go and<br />
checkout all the magic that CSS Media Queries can do.<br />
Adding Content to the Structure<br />
Earlier we setup the Index.cshtml, now that we have the<br />
Controller in place, we can build and run the application.<br />
Basic Styling<br />
By default, it looks up my ‘timeline’ for images I may have posted,<br />
and it shows one image per line, something like the following:<br />
We add the consumerKey and consumerSecret and add it to the<br />
instance of SessionStateCredentials(). Next we initialize the auth<br />
object and try to CompleteAuthorization. If authorization fails<br />
(session expired or first attempt), it reinitiates the authorization<br />
process by calling BeginAuthorization.<br />
Once Authorization is done, we create an instance of<br />
TwitterContext(auth) and query it to get list of Tweets for the<br />
provided screenName. Our Linq query transforms the ‘Status’<br />
object returned by the LINQ query into a TweetViewModel<br />
object. The GetTweetMediaUrl(…) extracts the URL of the Image<br />
if the Tweet has any images associated with it.<br />
private string GetTweetMediaUrl(Status status)<br />
Image provided by Sumit Maitra<br />
52 | DNCmagazine www.dotnetcurry.com