Sabre 开发 API 集成

问题描述 投票:0回答:1

我正在尝试使用 PHP 和我的测试凭据与 Sabre 的 api 集成。但是,我收到此响应“Array ( [error] => invalid_client [error_description] => Wrong clientID or clientSecret )”。

Sabre 文档: https://developer.sabre.com/docs/rest_apis/session_management/token_create_api/v2

https://developer.sabre.com/guides/travel-agency/developer-guides/rest-apis-token-credentials

对我的代码有任何建议或帮助,我们将不胜感激。 $saberUrl = 'https://api.platform.sabre.com/v2/auth/token';

$credentials = [
    'user_id' => 'V1:uname:DEVCENTER:AA',
    'password' => 'pwd'
];

$base64EncodeConcat =base64_encode(base64_encode($credentials['user_id']) . ':' . base64_encode($credentials['password']));

// Initialize cURL session
$curl = curl_init($saberUrl);

// Set cURL options
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
  'Content-Type: application/x-www-form-urlencoded',
  'Authorization: Basic ' . $base64EncodeConcat
));

// Include the grant_type parameter in the POST fields
curl_setopt($curl, CURLOPT_POSTFIELDS, "grant_type=client_credentials");

// Execute cURL session
$response = curl_exec($curl);

// Close cURL session
curl_close($curl);

// Process the response
$data = json_decode($response, true);

// Output the data
print_r($data);
php api sabre
1个回答
0
投票

您似乎在为 Sabre API 生成正确的身份验证标头时遇到了问题。根据 Sabre 的文档,您需要使用 base64 编码的客户端 ID 和客户端密钥,而不仅仅是用户 ID 和密码。凭据通常以客户端 ID 和客户端密钥的形式提供,这与您的用户凭据不同。

$saberUrl = 'https://api.platform.sabre.com/v2/auth/token';

$client_id = 'YOUR_CLIENT_ID'; // Use the client ID provided by Sabre
$client_secret = 'YOUR_CLIENT_SECRET'; // Use the client secret provided by Sabre

// Base64 encode client_id and client_secret
$base64EncodeConcat = base64_encode($client_id . ':' . $client_secret);

// Initialize cURL session
$curl = curl_init($saberUrl);

// Set cURL options
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/x-www-form-urlencoded',
    'Authorization: Basic ' . $base64EncodeConcat
));

// Include the grant_type parameter in the POST fields
curl_setopt($curl, CURLOPT_POSTFIELDS, "grant_type=client_credentials");

// Execute cURL session
$response = curl_exec($curl);

// Check for errors
if ($response === false) {
    $error = curl_error($curl);
    curl_close($curl);
    die('cURL Error: ' . $error);
}

// Close cURL session
curl_close($curl);

// Process the response
$data = json_decode($response, true);

// Output the data
print_r($data);

还要确保您使用正确的客户端 ID 和客户端密钥。这些与您在 Sabre 开发人员中心的用户凭据(用户名和密码)不同。如果您仍然遇到问题,请仔细检查您的凭据是否正确,并确认您使用的是正确的环境(沙箱)与生产)。

检查Sabre 的令牌生成 API 文档以确保您的配置正确。

© www.soinside.com 2019 - 2024. All rights reserved.