views:

28

answers:

1

Hey guys...

Im trying to fetch a feed from a Page in Facebook which works fine if i use a browser to get the feed - But when im trying to build a script that has to fetch the XML, it returns HTML, any ideas why ? And is there any other way to get the XML for a Fan feed??

The C# code is:

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`

When getting the response from Facebook i get an HTML page, with a response that it's an incompatible browser im coming from - If that is the case, then how do i get the feed ?

+1  A: 

What if you pretend the client is a known browser like IE by passing its User-Agent header:

web.Headers["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)";
Kwebble
Great, that worked like a charm :) Thx
Nicky