Facebook Graph API: удаленный сервер возвратил ошибку: (400) Bad Request вместо ошибки внутри - PullRequest
0 голосов
/ 06 ноября 2018

У меня есть код, который отправляет запрос Get в 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..

Должно быть возвращено сообщение об ошибке:

{
  "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 это то, что я получаю

Может кто-нибудь, пожалуйста, помогите мне?

Большое спасибо!

1 Ответ

0 голосов
/ 07 ноября 2018

Я нашел идею и уловил внутреннее исключение из оператора try / catch

Должно быть так:

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