【发布时间】:2022-01-08 14:26:32
【问题描述】:
我正在尝试为在线投资经纪人 Questrade 编写一个使用公共 API 的程序。
您在网站上手动生成刷新令牌,然后将其传递给请求以获取访问令牌。
Use the token you copied to redeem it for an access token and the server or practice server URL using the following command:
https://login.questrade.com/oauth2/token?grant_type=refresh_token&refresh_token=
or
https://practicelogin.questrade.com/oauth2/token?grant_type=refresh_token&refresh_token=
我在 postman 中构造了如下的 GET 请求,它成功并接收到一个有效的 json 正文。
https://login.questrade.com/oauth2/token?grant_type=refresh_token&refresh_token=MT1men5gBhSXyv15e6j7gC4CrD8msq3P0
在 dart 中,我按如下方式构造请求...
static Future<AccessToken> getAccessToken(String refreshToken) async {
var uri = Uri.https("login.questrade.com", "/oauth2/token?grant_type=refresh_token&refresh_token=$refreshToken");
var response = await http.get(uri);
print(response);
var json = jsonDecode(response.body);
return AccessToken.fromJson(json);
}
但它给我的只是一个实际的 html 响应,看起来像是一个登录页面(太大而无法发布)。
所以看起来端点对这些请求的处理方式不同,但我无法弄清楚这两个请求有什么不同......
【问题讨论】: