【发布时间】:2021-03-18 14:57:05
【问题描述】:
想知道我做错了什么。我正在尝试请求令牌以开始在 Angular 应用程序内使用 API。我已经成功地使用了您提供的 nodeJS SDK,但我想弄清楚如何使用 Angular 自己做这件事是一个额外的挑战,因为我并不精通 OAuth 的东西。显然我使用的客户 ID 和密码不同,但想避免在此处发布它们
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
})
};
data = "grant_type=client_credentials&client_id={1234567897}&client_secret={123456}"
getAmadeusAuthToken(): Observable<any> {
let headers = new HttpHeaders();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
return this.http.post('https://test.api.amadeus.com/v1/security/oauth2/token', this.data, this.httpOptions)
}
我也尝试过以不同的方式格式化正文:
data = {
grant_type: 'client_credentials',
client_id: '1234567897',
client_secret: '123456',
}
也试过这个:
data = "grant_type=client_credentials&client_id=1234567897&client_secret=123456"
但我总是遇到同样的错误:
code: 38187
error: "invalid_client"
error_description: "Client credentials are invalid"
title: "Invalid parameters"
message: "Http failure response for https://test.api.amadeus.com/v1/security/oauth2/token:
401 Unauthorized"
name: "HttpErrorResponse"
ok: false
status: 401
statusText: "Unauthorized"
url: "https://test.api.amadeus.com/v1/security/oauth2/token"
为了确保我没有输入错误的客户端 ID 或 Secret,我在您提供的 nodeJS SDK 中输入了相同的 ID,并且它可以正常工作。任何形式的帮助将不胜感激。我确定我在发布请求时做错了。
【问题讨论】:
-
仅供参考,因为您一直说“您提供了”--> 这不是对任何公司的技术支持。这是一个公共问答网站;我们没有提供任何东西。 :)
-
啊,是的,抱歉,我通过此处标记 Amadeus 以获得支持,因为您可以通过这种方式请求有关 API 相关问题的帮助,但我想通了,抱歉,如果我在帖子中听起来很笨拙