我正在使用MVC 4在asp.net中创建一个Web应用程序,我正在尝试向用户显示用户的twitter主页。要获取用户主页Feed,我正在使用twitterizer2。一切正常,我有用户家庭饲料和饲料照片链接,但它不会显示在浏览器中。如果我从浏览器地址栏打开图片链接,它会显示,如果我使用另一个与twitter无关的照片链接,一切正常。所以我猜它与推特有关。
我的观点是:
<div class="NoBullets" style="font-size:@Model.TextSize">
<ul style="list-style-type:none">
@foreach (var status in Model.TStatusCollection)
{
<li>
<a href="http://twitter.com/#!/@status.User.ScreenName"><img src=@status.User.ProfileImageLocation style="float:left" width="48" height="48" align="bottom"> @status.Text</a><br />
@string.Format("{0:dd MMMM yyyy} {0:H:mm}", status.CreatedDate)
</li>
}
</ul>
</div>
模特:
public class PortletMyTwitter : PortletBase
{
private int noOfTweets = 15;
private string textSize = "medium";
private string userExtAppID;
private TwitterStatusCollection tStatusCollection;
private IList<object> noOfTweetsList = new List<object>()
{
new {value = 5},
new {value = 10},
new {value = 15},
new {value = 20},
new {value = 25}
};
private IList<object> textSizeList = new List<object>()
{
new {value = "small"},
new {value = "medium"},
new {value = "large"}
};
public string UserExtAppID
{
get { return userExtAppID; }
set { userExtAppID = value; }
}
public IList<object> NoOfTweetsList
{
get { return noOfTweetsList; }
}
public int NoOfTweets
{
get { return noOfTweets; }
set { noOfTweets = value; }
}
public IList<object> TextSizeList
{
get { return textSizeList; }
}
public string TextSize
{
get { return textSize; }
set { textSize = value; }
}
public TwitterStatusCollection TStatusCollection
{
get { return tStatusCollection; }
}
public void GetSettings(XmlDocument xmlPortletState)
{
if (xmlPortletState.GetElementsByTagName("UserExtAppID").Count > 0)
{
if (xmlPortletState.GetElementsByTagName("UserExtAppID")[0].FirstChild != null)
UserExtAppID = ((System.Xml.XmlText)(xmlPortletState.GetElementsByTagName("UserExtAppID")[0]).FirstChild).Value;
}
if (xmlPortletState.GetElementsByTagName("HideHeader").Count > 0)
{
if (xmlPortletState.GetElementsByTagName("HideHeader")[0].FirstChild != null)
HideHeader = bool.Parse(((System.Xml.XmlText)(xmlPortletState.GetElementsByTagName("HideHeader")[0]).FirstChild).Value);
}
if (xmlPortletState.GetElementsByTagName("TextSize").Count > 0)
{
if (xmlPortletState.GetElementsByTagName("TextSize")[0].FirstChild != null)
try
{
TextSize = ((System.Xml.XmlText)(xmlPortletState.GetElementsByTagName("TextSize")[0]).FirstChild).Value;
}
catch
{
TextSize = "medium";
}
}
if (xmlPortletState.GetElementsByTagName("NoOfTweets").Count > 0)
{
if (xmlPortletState.GetElementsByTagName("NoOfTweets")[0].FirstChild != null)
try
{
NoOfTweets = Convert.ToInt32(((System.Xml.XmlText)(xmlPortletState.GetElementsByTagName("NoOfTweets")[0]).FirstChild).Value);
}
catch
{
NoOfTweets = 10;
}
}
UpdateFeed();
}
protected void UpdateFeed()
{
try
{
OAuthTokens oauthTokens = new OAuthTokens()
{
AccessToken = "",
AccessTokenSecret = "",
ConsumerKey = "",
ConsumerSecret = ""
};
TimelineOptions myOptions = new TimelineOptions();
myOptions.IncludeRetweets = false;
myOptions.UseSSL = true;
myOptions.APIBaseAddress = "https://api.twitter.com/1.1/";
myOptions.Count = NoOfTweets;
TwitterResponse<TwitterStatusCollection> twitterDataSource = TwitterTimeline.HomeTimeline(oauthTokens, myOptions);
tStatusCollection = twitterDataSource.ResponseObject;
}
catch (Exception)
{
}
}
}