【问题标题】:Amadeus api return 401 client Credentials are invalidAmadeus api 返回 401 客户端凭据无效
【发布时间】:2018-11-12 11:20:43
【问题描述】:

Amadeus api 返回401 client Credentials are invalid。请检查下面的代码。我将符号 [] 包含在凭据字符串中。

// here xxxxx are placeholders for real credentials (strings)
Amadeus amadeus = Amadeus.builder("[xxxxxx]","[xxxxxx]")
                    .setHostname("test").setHost("test.api.amadeus.com").setSsl(true).setLogLevel("debug").build();

//HttpHandler sh = new HttpHandler();

//FlightDestination[] des = sh.FlightDest();
//id = sh.id();

try {

    FlightDestination[] destination1 = amadeus.shopping.flightDestinations.get(Params.with("origin", "LON"));


    id = destination1[0].getOrigin();
    name = destination1[0].getDestination();
    email = destination1[0].getType();
}catch (ClientException e)
{
    id=e.getMessage();

}catch (NetworkException e)
{
    id = e.getMessage();

}catch (NotFoundException e)
{
    id = e.getMessage();
}catch (ServerException e)
{
   id =  e.getMessage();
}catch (ParserException e)
{
    id = e.getMessage();
}catch (ResponseException e)
{
    id = e.getMessage();
}

【问题讨论】:

  • 尝试删除凭据周围的 [ ],另外,不要在此处发布您的凭据
  • 当我从凭据中删除 [ ] 时,我的应用程序崩溃了。任何建议的解决方案将不胜感激。谢谢

标签: amadeus


【解决方案1】:

您不需要 [ ],您需要将它们替换为您在this guide 之后获得的 API_KEY 和 API_SECRET。

您可以找到使用 Java SDK herehere 的示例。

Amadeus amadeus = Amadeus.builder("API_KEY", "API_SECRET").build();


/* Find cheapest destinations from London */

FlightDestination[] flightDestinations = amadeus.shopping.flightDestinations.get(Params.with("origin", "LON"));

System.out.println(flightDestinations[0]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-25
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多