facebook-graph-api - Facebook Graph API:远程服务器返回错误:(400) Bad Request 而不是内部错误
问题描述
我有一个代码向 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
是我得到的
有人可以帮我吗?
非常感谢!
解决方案
我找到了一个想法并从 try/catch 语句中捕获了内部异常
它应该是这样的:
catch (WebException ex)
{
using (StreamReader reader = new StreamReader(ex.Response.GetResponseStream()))
{
string jsonMessageString = reader.ReadToEnd();
}
}
推荐阅读
- javascript - 如何在我的所有网页上显示叠加层?
- php - 通过 Symfony/Console 创建不同类型的类
- php - 如何更改数组中的值?
- c++ - 当捕获 lambda 仿函数在另一个作用域/函数中被调用时,实际上会发生什么?
- c# - 如何将图像上传到 LinkedIn 以在 C# 中发布 Ugc 图像
- python - 将二进制值转换为日期时间 python
- javascript - 尝试使用按钮切换布尔变量
- angular - 为什么我使用获取请求角度时出错?
- php - 使用 cURL 和 PHP 连接 api.dynadot.com 失败
- javascript - 如何获取用户的表单输入并将其用于事件元素?