Amadeus API身份验证 [英] Amadeus API Authentication

查看:154
本文介绍了Amadeus 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​​密钥和秘密密钥进行一些编码,但是我在文档中找不到任何内容

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.

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

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