【问题标题】:Facebook Fan Page feedFacebook 粉丝页面提要
【发布时间】:2011-04-05 15:53:03
【问题描述】:

我试图从 Facebook 中的页面获取提要,如果我使用浏览器获取提要,这可以正常工作 - 但是当我尝试构建必须获取 XML 的脚本时,它返回 HTML,有什么想法吗?还有其他方法可以获取 Fan feed 的 XML 吗??

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 页面,它的响应是来自不兼容的浏览器 - 如果是这种情况,那么我如何获取提要?

【问题讨论】:

  • 我猜你没有提供所需的与身份验证相关的 cookie。然后服务器将重定向到登录页面。

标签: c# facebook rss feed


【解决方案1】:

如果您通过传递其 User-Agent 标头来假装客户端是已知的浏览器(如 IE):

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-03
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-25
    • 2023-03-07
    • 1970-01-01
    相关资源
    最近更新 更多