【发布时间】:2021-02-16 10:47:17
【问题描述】:
编辑:我找到了解决方案并回答了问题。
我正在我的应用程序中尝试 POST 到 Instagram 的 API。 POST 在 Postman 中运行良好,但在我的颤动代码中,我总是收到错误响应:{error_type: OAuthException, code: 400, error_message: Invalid platform app}。我的颤振POST一定是做错了什么,但我不知道是什么。
这是我的 Dart/Flutter 代码,它给了我错误:
var clientID = '708XXXXXXXX';
var clientSecret = '37520XXXXXXXXXXXXX';
var grantType = 'authorization_code';
var rediUrl = 'https://httpstat.us/200';
var urlTwo = 'https://api.instagram.com/oauth/access_token';
var body = json.encode({
'client_id': clientID,
'client_secret': clientSecret,
'grant_type': grantType,
'redirect_uri': rediUrl,
'code': _accessCode
});
print('Body: $body');
var response = await http.post(urlTwo,
headers: {
'Accept': '*/*',
'Content-Type': 'application/json',
},
body: body,
);
print(json.decode(response.body));
我在另一个线程上读到了这个错误,他们说要发布为 x-www-formurlencoded.. 当我将 Content-Type 切换到这个时,我得到了同样的错误。
我在 Flutter 中遇到的错误:
{error_type: OAuthException, code: 400, error_message: Invalid platform app}
我进行了三次检查,并且在 Postman 和 Flutter 中使用了所有相同的值。我已经尝试将值作为字符串和数字。
当我打印正文时:
Body: {"client_id":"70000edited","client_secret":"37520634edited","grant_type":"authorization_code","redirect_uri":"https://httpstat.us/200","code":"AQCs-H3cIU0aF1o2KkltLuTmVMmJ-WJnZIhb9ryMqYedited"}
【问题讨论】:
-
您是否尝试像这样更改redirect_uri:localhost:5001
-
@Akif 不,redirect-uri 必须与我在 Facebook 开发人员仪表板中设置的 URL 匹配,我设置的那个在 Postman 中运行良好。我使用的那个会自动发送 200 响应进行测试。
标签: flutter dart http-post postman