艾玛迪斯 API 身份验证 [英] Amadeus API Authentication

查看:18
本文介绍了艾玛迪斯 API 身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是尝试向 amadeus API 发出请求

I just try make an request against amadeus API

我已经有了 API KEY 和 API Secret,我传入了 XHR 头使用我的 API 密钥值授权

I already have API KEY and API Secret, I pass in XHR header Authorization with value of my API key

这是我的 JQuery:

This is my JQuery:

$.ajax({
            type: "get",
            url: "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MIA&destination=SFOˆduration=15&nonStop=true",
            dataType: 'json',
            async: true,
            beforeSend: function(xhr) {
                xhr.setRequestHeader('Authorization',
                    'Basic ' + amadeusApiKey);
            },                
            success: function(json) {
                console.log(json);
            }
        });

但响应是 HTTP 代码 401 和正文

but the response is HTTP code 401 and body

    {
    "errors": [
      {
        "code": 38190,
        "title": "Invalid access token",
        "detail": "The access token provided in the Authorization header is invalid",
        "status": 401
      }
    ],
}

我是否应该使用 API Key 和 Secret Key 进行一些编码,我在文档中找不到任何内容

Should I make some encode with the API Key and Secret Key, I don`t find anything in the documentation

推荐答案

您尝试定位的 API 使用 客户端凭据授予类型.

The API you are trying to target is secured using Client credentials grant type.

在进行调用之前,您应该使用 API 密钥/秘密生成访问令牌,请参阅此 指南.生成访问令牌后,您的请求应如下所示:

Before making the call, you should generate an access token using your API key/secret, please refer to this guide. Once you have generated an access token, your request should look like:

$.ajax({
        type: "get",
        url: "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MIA&destination=SFOˆduration=15&nonStop=true",
        dataType: 'json',
        async: true,
        beforeSend: function(xhr) {
            xhr.setRequestHeader('Authorization',
                'Bearer ' + amadeusAccessToken);
        },                
        success: function(json) {
            console.log(json);
        }
    });

或者,Amadeus 提供了一些 SDK 来抽象这种复杂性.

Alternatively, Amadeus provides some SDKs to abstract this complexity.

这篇关于艾玛迪斯 API 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆