array( 'method' => 'POST' , 'content' => http_build_query( array( 'grant_type' => 'refresh_token' , "refresh_token" => $refresh_token , 'client_id' => $client_id , 'client_secret' => $client_secret , ) ) , ) , ) ; // スコープが指定されている場合 if( isset($scope) && !empty($scope) ) { $context['http']['content']['scope'] = $scope ; } // CURLを使ってリクエスト $curl = curl_init() ; // オプションのセット curl_setopt( $curl , CURLOPT_URL , 'https://api.moves-app.com/oauth/v1/access_token' ) ; curl_setopt( $curl , CURLOPT_HEADER, 1 ) ; curl_setopt( $curl , CURLOPT_CUSTOMREQUEST , $context['http']['method'] ) ; // メソッド curl_setopt( $curl , CURLOPT_SSL_VERIFYPEER , false ) ; // 証明書の検証を行わない curl_setopt( $curl , CURLOPT_RETURNTRANSFER , true ) ; // curl_execの結果を文字列で返す curl_setopt( $curl , CURLOPT_POSTFIELDS , $context['http']['content'] ) ; // リクエストボディ curl_setopt( $curl , CURLOPT_TIMEOUT , 5 ) ; // タイムアウトの秒数 // 実行 $res1 = curl_exec( $curl ) ; $res2 = curl_getinfo( $curl ) ; // 終了 curl_close( $curl ) ; // 取得したデータ $json = substr( $res1, $res2['header_size'] ) ; // 取得したデータ(JSONなど) $header = substr( $res1, 0, $res2['header_size'] ) ; // レスポンスヘッダー (検証に利用したい場合にどうぞ) // オブジェクトに変換 $obj = json_decode( $json ) ; // HTML用 $html = '' ; // エラー判定 if( !isset($obj->access_token) || !isset($obj->refresh_token) ) { $html .= '

トークンを取得できませんでした…。

' ; } else { // トークン $access_token = $obj->access_token ; $refresh_token = $obj->refresh_token ; // 出力 $html .= '
' ; $html .= '
新しいアクセストークン
' ; $html .= '
' . $access_token . '
' ; $html .= '
新しいリフレッシュトークン
' ; $html .= '
' . $refresh_token . '
' ; $html .= '
' ; } // 取得したデータ $html .= '

取得したデータ

' ; $html .= '

下記のデータを取得できました。

' ; $html .= '

JSON

' ; $html .= '

' ; $html .= '

レスポンスヘッダー

' ; $html .= '

' ; ?> Moves APIで、アクセストークンをリフレッシュするサンプルデモ

配布元: Syncer