2010-08-30 151 views
0

即时通讯设法从Facebook中的页面提取饲料,如果我使用浏览器来获取饲料,那么工作正常 - 但是当我试图建立一个脚本来获取XML时,它会返回HTML,任何想法为什么?是否有任何其他方式来获得一个粉丝饲料的XML?使用此URLFacebook粉丝页面订阅

的C#代码:

private string GetFacebookPosts(string FacebookID, int NumberOfPosts) 
    { 

     string feedadress = "http://www.facebook.com/feeds/page.php?format=atom10&id=" + FacebookID.ToString(); 
     WebClient web = new WebClient(); 
     return web.DownloadString(feedadress); 
    } 

    #region Module rendering 

    /// <summary> 
    /// Renders the module output XML for frontend 
    /// </summary>  
    protected override string Render(Page page) 
    { 
     string FacebookResponse = GetFacebookPosts(ModuleEditionInstance.FacebookID, ModuleEditionInstance.NumberOfPosts); 

     XmlDocument FacebookXML = new XmlDocument(); 
     FacebookXML.LoadXml(FacebookResponse); 


     // Transform the rendered xml with the current XslSnippet 
     return ApplyXslSnippet(FacebookXML.InnerXml, page); 
    } 

    #endregion` 

当接收来自Facebook我得到一个HTML页面的响应,这是一个不兼容的响应浏览器im来自 - 如果是这样的话,那么我如何得到饲料?

+0

我的猜测是你没有提供所要求的认证相关的cookie。服务器将重定向到登录页面。 – Foole 2010-08-30 10:28:45

回答

2

如果你假装客户端什么是已知的浏览器如IE通过将它的User-Agent头:

web.Headers["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)"; 
+0

太棒了,就像一个魅力:) Thx – Nicky 2010-08-30 12:48:24