3

I am trying to get facebook page feed ( public posts) which does not require any access token. here's the url https://www.facebook.com/feeds/page.php?format=json&id=1393547494231876 when i run this in browser where id= any facebook page id. it returns first 25 public posts in json format. but when i run this in my code to get json result facebook return a page saying "unsupported browser" this is my method . i pass it facebook page id to get posts..

public static String GetPosts(string PageId)
    {
        string id = PageId;
        string apilink = "https://www.facebook.com/feeds/page.php?format=json&id=";
        HttpWebRequest request = WebRequest.Create(apilink + id) as HttpWebRequest;
        request.Method = WebRequestMethods.Http.Get;
        request.Accept = "application/json";
        request.ContentType = "application/json; charset=utf-8";
        // Get response  
        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        {
            // Get the response stream  
            StreamReader reader = new StreamReader(response.GetResponseStream());

            // Console application output  
            String result = reader.ReadToEnd();
            return result;
        }
    }

Here's the result that i get in return string Result Image String

and so on remaining page returned. Can somebody help me how to get it working??

Update Found Answer... I Have To Set User agent to make Facebook think i am a browser.. so just added request.UserAgent = ".NET Framework"; and i worked. Thanks to All.

Hafiz Bilal
  • 113
  • 9
  • What browser do you use? – Lajos Arpad Feb 19 '14 at 13:49
  • for checking the url you can use any browser... actually i'm requesting the url to give me the page content that it returned on brwser. in asp.net 4.0 in above function u can see that.i use chrome as my default – Hafiz Bilal Feb 19 '14 at 15:28
  • Try setting request.UserAgent to your browsers user agent string - this should make facebook think your web request is from a browser it recognises and send an appropriate response - see here http://stackoverflow.com/questions/3057328/httpwebrequest-useragent-what-does-it-do – Luke Baughan Feb 19 '14 at 16:01
  • just 30 mins ago i also found answer from a colleague..... as u said i have to set request.UserAgent and i set it to request.UserAgent = ".NET Framework"; and it worked.. thanks again... – Hafiz Bilal Feb 19 '14 at 16:09
  • @HafizBilal you can add answer to your own question... this will be helpful for someone who have same issue... – Aamir Shahzad Mar 11 '14 at 17:39

1 Answers1

4

Found Answer... I Have To Set User agent to make Facebook think i am a browser.. so just added request.UserAgent = ".NET Framework"; and i worked. Thanks to All.

Hafiz Bilal
  • 113
  • 9
  • facebook does not return all posts in single request rather only top few requests returned. any way to get all posts or count of page posts? – Adeem Mar 20 '14 at 12:03