使用 Bearer Auth 令牌从我的代码调用 Airport & City Search amadeus 自助服务 API 时出现 403 Forbidden 异常

Getting 403 Forbidden exception while calling the Airport & City Search amadeus self service API from my code with Bearer Auth token

我正在从 Spring 引导应用程序调用没有 JAVA SDK 的 amadeus self-service APIs。 在第一次调用中,我通过调用授权 API 成功获得了 access_token。现在 access_token 如果我调用机场和城市搜索,我会收到此回复。

{
    "errors": [
        {
            "code": 38197,
            "title": "Forbidden",
            "detail": "Access forbidden",
            "status": 403
        }
    ]
}

我在请求 header 中将 access_token 作为不记名令牌传递。下面是我的代码。

public String getCityList(String keyword) throws Exception {
        HttpHeaders headers = new HttpHeaders();
        headers.setBearerAuth(authToken);
        HttpEntity<String> entity = new HttpEntity<String>(headers);
        String url = "http://test.api.amadeus.com/v1/reference-data/locations?subType=AIRPORT,CITY&keyword=" + keyword
                + "&page[limit]=5";
        String body = restTemplate.exchange(url, HttpMethod.GET, entity, String.class).getBody();

        return body;
}

同样的标记在 Postman 上运行良好。

我是不是漏掉了什么?

提前致谢。

您正在使用 http 而不是 https 作为 url。