Facebook Graph API:远程服务器返回错误:(400)请求错误,而不是内部错误



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

这是代码:

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是我得到的

有人能帮我吗?

非常感谢!

我发现了一个想法,并从try/catch语句中捕获了内部异常

应该是这样的:

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

最新更新