sabre生产api php-需要帮助-由于凭据无效,身份验证失败

sabre生产api php-需要帮助-由于凭据无效,身份验证失败,php,sabre,Php,Sabre,调用SabreRESTAPI时,我收到以下消息 array(3) { ["access_token"]=> string(252) "my_accesstoken_was_here" ["token_type"]=> string(6) "bearer" ["expires_in"]=> int(604800) } 我遵循了此处的sabre文档: 我不知道为什么会收到无效凭据消息,因为我使用的是sabre的API调用提供的访问令牌 下面是我的代码。问题是什么 <?ph

调用SabreRESTAPI时,我收到以下消息

array(3) { ["access_token"]=> string(252) "my_accesstoken_was_here" ["token_type"]=> string(6) "bearer" ["expires_in"]=> int(604800) }

我遵循了此处的sabre文档:

我不知道为什么会收到无效凭据消息,因为我使用的是sabre的API调用提供的访问令牌

下面是我的代码。问题是什么

<?php

//  get access token 
$client_id= base64_encode("V1:user:group:AA");
$client_secret = base64_encode("my_password");
$token = base64_encode($client_id.":".$client_secret);

$data='grant_type=client_credentials';


    $headers = array(
        'Authorization: Basic '.$token,
        'Accept: */*',
        'Content-Type: application/x-www-form-urlencoded'
    );

    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,"https://api.sabre.com/v2/auth/token");
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch,CURLOPT_POST,1);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $res = curl_exec($ch);
    curl_close($ch);
    var_dump($resf = json_decode($res,1));
    $access_token = $resf['access_token']; // token provided from sabre
    $token_type = $resf['token_type'];
    $expires_in_seconds = $resf['expires_in'];

    // //  END get access token 

    // now to get api data using the provided access token
    $url = 'https://api.test.sabre.com/v1/shop/flights/fares?origin=jfk&destination=lax&lengthofstay=5&pointofsalecountry=US';
    $headers2 = array(
    'Authorization: bearer '.$access_token,
    'protocol: HTTP 1.1 '
     );

    echo "<br><br>";
    $ch2 = curl_init();
    curl_setopt($ch2,CURLOPT_URL,$url);
    curl_setopt($ch2,CURLOPT_HTTPHEADER,$headers2);
    curl_setopt($ch2,CURLOPT_RETURNTRANSFER,1);
    var_dump(json_decode(curl_exec($ch2),1));
    curl_close($ch2);


?>

问题在于,您正在请求一个PROD访问令牌(api.sabre.com),但将随后的调用发送到测试环境(api.test.sabre.com)。请记住,PROD和TEST凭证和令牌是不可互换的

如果您发送第二个呼叫到api.sabre.com,您应该会没事的

希望这有帮助。
布鲁诺

是的,这就是问题所在。非常感谢你,布鲁诺。
<?php

//  get access token 
$client_id= base64_encode("V1:user:group:AA");
$client_secret = base64_encode("my_password");
$token = base64_encode($client_id.":".$client_secret);

$data='grant_type=client_credentials';


    $headers = array(
        'Authorization: Basic '.$token,
        'Accept: */*',
        'Content-Type: application/x-www-form-urlencoded'
    );

    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,"https://api.sabre.com/v2/auth/token");
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch,CURLOPT_POST,1);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $res = curl_exec($ch);
    curl_close($ch);
    var_dump($resf = json_decode($res,1));
    $access_token = $resf['access_token']; // token provided from sabre
    $token_type = $resf['token_type'];
    $expires_in_seconds = $resf['expires_in'];

    // //  END get access token 

    // now to get api data using the provided access token
    $url = 'https://api.test.sabre.com/v1/shop/flights/fares?origin=jfk&destination=lax&lengthofstay=5&pointofsalecountry=US';
    $headers2 = array(
    'Authorization: bearer '.$access_token,
    'protocol: HTTP 1.1 '
     );

    echo "<br><br>";
    $ch2 = curl_init();
    curl_setopt($ch2,CURLOPT_URL,$url);
    curl_setopt($ch2,CURLOPT_HTTPHEADER,$headers2);
    curl_setopt($ch2,CURLOPT_RETURNTRANSFER,1);
    var_dump(json_decode(curl_exec($ch2),1));
    curl_close($ch2);


?>