[英]PayPal PHP SDK: Authentication failed due to invalid authentication credentials or a missing Authorization header
[英]sabre production api php - need help - Authentication failed due to invalid credentials
調用saber rest API時收到以下消息。
array(3) { ["access_token"]=> string(252) "my_accesstoken_was_here" ["token_type"]=> string(6) "bearer" ["expires_in"]=> int(604800) }
array(5) { ["status"]=> string(12) "NotProcessed" ["type"]=> string(10) "Validation" ["errorCode"]=> string(31) "ERR.2SG.SEC.INVALID_CREDENTIALS" ["timeStamp"]=> string(29) "2016-10-17T07:06:40.053-05:00" ["message"]=> string(48) "Authentication failed due to invalid credentials" }
我遵循了位於此處的saber文檔: https : //developer.sabre.com/docs/read/rest_basics/authentication
我不知道為什么要使用無效的憑證消息,因為我正在使用從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,則應該沒問題。
希望這可以幫助。 布魯諾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.