2010-08-02 4 views
2

ASP/C#을 사용하여 빌드 된 사이트를 수정하는 중이고 그 중 하나는 2 개의 RSS 피드 (사이트의 내부 블로그, 다른 하나는 사이트의 Twitter 계정에서 가져온 것입니다. 그러나 피드의 올바른 URL을 가리키고 있음을 확인 했음에도 불구하고 계속 두 피드에서 빈 피드를 얻는 것 같습니다. 내 코드는 아래와 같습니다.ASP 및 C#에서 RSS 피드 사용

private void GetTwitterRSS() 
{ 
    IEnumerable items = Cache["TwitterFeed"] as List<SyndicationItem>; 

    if (items == null) 
    { 
     try 
     { 
      SyndicationFeed blogFeed = SyndicationFeed.Load(XmlReader.Create("http://twitter.com/statuses/user_timeline/84668697.rss")); 
      items = blogFeed.Items; 
     } 
     catch 
     { 
      items = new List<SyndicationItem>(); 
     } 
     Cache.Insert("TwitterFeed", items, null, DateTime.Now.AddMinutes(5.0),TimeSpan.Zero); 
     twitterrssRepeater.DataSource = items; 
     twitterrssRepeater.DataBind(); 
    } 
} 

private void GetBlogRSS() 
{ 
    IEnumerable items = Cache["BlogFeed"] as List<SyndicationItem>; 

    if (items == null) 
    { 
     try 
     { 
      SyndicationFeed blogFeed = SyndicationFeed.Load(XmlReader.Create("http://www.rentseeker.ca/blog/?feed=rss2")); 
      items = blogFeed.Items; 
     } 
     catch 
     { 
      items = new List<SyndicationItem>(); 
     } 
     Cache.Insert("BlogFeed", items, null, DateTime.Now.AddHours(1.0),TimeSpan.Zero); 
     blogrssRepeater.DataSource = items; 
     blogrssRepeater.DataBind(); 
    } 
} 

protected string DisplayBlogFeedItem(SyndicationItem item) 
{ 
    return string.Format(@"<p>{1}</p><p><strong>{2}</strong></p><p>{3}</p>", 
     FormatPublishDate(item.PublishDate.DateTime), 
     item.Title.Text, 
     item.Summary.Text); 
} 

protected string DisplayTwitterFeedItem(SyndicationItem item) 
{ 
    return string.Format(@"<li>{1}</li>", 
     item.Title.Text); 
} 

페이지의 코드는 다음과 같습니다

<ul> 
    <asp:ListView ID="twitterrssRepeater" runat="server"> 
     <ItemTemplate> 
      <%# DisplayTwitterFeedItem((Container as ListViewDataItem).DataItem as System.ServiceModel.Syndication.SyndicationItem) %> 
     </ItemTemplate> 
    </asp:ListView> 
</ul> 

하고 명확하게

<asp:ListView ID="blogrssRepeater" runat="server"> 
    <ItemTemplate> 
     <%# DisplayBlogFeedItem((Container as ListViewDataItem).DataItem as System.ServiceModel.Syndication.SyndicationItem) %> 
    </ItemTemplate> 
</asp:ListView> 

, 내가 모르는 뭔가가있어. 내가 읽은 것부터, 나는 트위터 피드를보기 위해 자신을 인증해야한다는 것을 이해한다. 나는 자격증을 가지고 있지만, 그것을로드 할 때 SyndicationFeed에 패스하는 방법을 모르겠다.

추가 정보를 얻으려는 요령, 제안 또는 지침은 크게 감사하겠습니다.

답변

4

여기 그런 다음 피드를 얻을 수있는 방법을 내 트위터 피드를 수신 할 때 사용하는 간단한 예제 (I 만 업데이트 제목을, & ID를 이름을 받고 있어요)

public class TwitterFeed 
{ 
    public string Name { get; set; } 
    public string Title { get; set; } 
    public string Id { get; set; } 
} 

public List<TwitterFeed> GetTwitterFeed(string name) 
{ 
    List<TwitterFeed> list = new List<TwitterFeed>(); 
    XmlReader reader = XmlReader.Create(string.Format("http://search.twitter.com/search.atom?q=to:{0}", name)); 
    SyndicationFeed feed = SyndicationFeed.Load(reader); 
    var tweetItems = from item in feed.Items 
      select new TwitterFeed() 
      { 
       Name = item.Authors.First().Name, 
       Title = item.Title.Text, 
       Id = item.Id 
      }; 

    return tweetItems.ToList(); 
} 

희망이 도움이

+0

내가 코드에서 본 유일한 차이점은 피드의 URL 주변 및 String.format()를 추가했다. 나는 피드에 두 항목이 모두 포함되어 있다는 사실에도 불구하고 표시되는 내용이 보이지 않는 것과 같은 결과로 추가하려고했습니다. – Elie

+0

흠, 나는 거의 손실에 빠졌는데, 그것은 내 트위터 피드에서 효과가있다. EDIT : 코드를 볼 때와 다른 URL을 사용할 때 http://twitter.com/statuses/user_timeline/84668697.rss를 사용하고 있으며 http : //search.twitter를 사용하고 있습니다. co.kr/search.atom? q = to : psychocoder. 사용중인 URL로 시도해보고 무슨 일이 일어나는지 확인하십시오. – PsychoCoder

+0

자세히 살펴보면 피드를 검색하고 ListView에 바인딩 할 때 연결이 끊어지는 것 같습니다. 나는 목록에있는 몇 가지 항목을 강제로 시도했지만 아무런 문제가 없으므로 RSS 관련 문제가 아니라 ListView 관련 문제 일 수 있습니다. – Elie

0

SyndicationFeed.Items는 목록이 아니지만 IEnumerable 인터페이스를 구현하므로

대신 (210)
IEnumerable items = Cache["BlogFeed"] as List<SyndicationItem>; 

다음 줄을 사용

IEnumerable items = Cache["BlogFeed"] as IEnumerable<SyndicationItem>;