Facebook Graph API: The remote server returned an error: (400) Bad Request instead of error inside

Facebook Graph API: The remote server returned an error: (400) Bad Request instead of error inside

我有一个代码可以向 Facebook Graph API 发出获取请求以获取企业帐户。

这是代码:

var facebookBusinessAccountId = ConfigurationManager.AppSettings["facebook_business_account_id"];
                            facebookRestUrl += "&access_token=" + acct.AccessToken;

                            facebookRestUrl = facebookRestUrl.Replace("{0}", facebookBusinessAccountId);

                            var request = WebRequest.Create(facebookRestUrl);
                            request.Method = "GET";
                            request.ContentType = "application/json";

                            var response = request.GetResponse(); (Error here)

URI 看起来像:

https://graph.facebook.com/v3.1/1x8xx4005xxxxxx?fields=business_discovery.username(yess_cub){biography,id,ig_id,profile_picture_url,username,website}&access_token=EAAJ..

应该是return这样的错误:

{
  "error": {
    "message": "Invalid user id",
    "type": "OAuthException",
    "code": 110,
    "error_subcode": 2207013,
    "is_transient": false,
    "error_user_title": "Cannot find User",
    "error_user_msg": "The user with username: yess_cub cannot be found.",
    "fbtrace_id": "BMEAcyYOZf9"
  }
}

但错误:The remote server returned an error: (400) Bad Request 是我得到的

有人能帮帮我吗?

非常感谢!

我找到了一个想法并从 try/catch 语句

捕获了内部异常

应该是这样的:

catch (WebException ex)
{
   using (StreamReader reader = new StreamReader(ex.Response.GetResponseStream()))
   {
      string jsonMessageString = reader.ReadToEnd();
   }
}