在 asp.net 中获取Facebook页面提要(使用图形API),收到错误"Unsupported Browser"



我正在尝试获取不需要任何访问令牌的Facebook页面提要(公共帖子)。这是网址https://www.facebook.com/feeds/page.php?format=json&id=1393547494231876当我在浏览器中运行它时,其中 id= 任何 Facebook 页面 ID。 它以 JSON 格式返回前 25 个公共帖子。但是当我在我的代码中运行它以获得 JSON 结果时,Facebook 返回一个页面,上面写着"不支持的浏览器"这是我的方法.我通过它脸书页面ID来获取帖子。

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;
        }
    }

这是我在返回字符串中得到的结果结果图像字符串

以此类推返回剩余页面。有人可以帮我如何让它工作吗?

更新找到答案...我必须设置用户代理,让Facebook认为我是一个浏览器。所以刚刚添加 请求。UserAgent = ".NET Framework";我工作了。 谢谢大家。

找到答案...我必须设置用户代理,让Facebook认为我是一个浏览器。所以刚刚添加了请求。UserAgent = ".NET Framework";我工作了。谢谢大家。

最新更新