0

私は現在旅行代理店のウェブサイトを作成しており、低運賃の検索などにAmadeusを使用していますが、アクセストークンが30分で期限切れになるたびに. ステータス 401 を取得します (アクセス トークンの有効期限が切れています)。そして、彼らのウェブサイトから別のアクセストークンを繰り返し要求し、それを私のコードに貼り付けます. コード内のアクセストークンを自動的に変更する解決策があるかどうかお尋ねしてもよろしいですか

私は現在、このコードを使用してアクセスコードをリクエストしています

**

$url = "https://test.api.amadeus.com/v1/security/oauth2/token";
$curls = curl_init();
curl_setopt($curls, CURLOPT_URL, $url);
curl_setopt($curls, CURLOPT_POST, true);
curl_setopt($curls, CURLOPT_POSTFIELDS, 'grant_type=client_credentials&client_id={apikey}&client_secret={apisecret}');
curl_setopt($curls, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
$token = curl_exec($curls);
curl_close($curls);
$tokenresult = json_decode($token,true);
print_r ($tokenresult);

**

しかし、ウェブサイトを更新するたびに表示されます

"type": "amadeusOAuth2Token",
            "username": "",
            "application_name": "Thesis",
            "client_id": "",
            "token_type": "Bearer",
            "access_token": "*****",
            "expires_in": 1799,
            "state": "approved",
            "scope": ""

これは非常に迷惑です。

これはaccess_tokenを使用した私のコードです

$ch = curl_init("https://test.api.amadeus.com/v1/shopping/flight-offers?origin=$client_flyingfrom&destination=$client_flyingto&departureDate=$client_departing&returnDate=$client_returning&nonStop=false&currency=PHP&max=2");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
   'Content-Type: application/json',
   'Authorization: Bearer *****' 
   ));
$data = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$json = json_decode($data,true);
print_r($json);

手伝って頂けますか?コードに新しいアクセス トークンをコピー アンド ペーストせずに、アクセス トークンを自動的に変更する方法はありますか? みんなありがとう

4

1 に答える 1