COTOHA API Portal の使用例です。
acess_token.php
#! /usr/bin/php
<?php
// ------------------------------------------------------------------
// access_token.php
//
// Feb/26/2020
//
// ------------------------------------------------------------------
include('Requests/library/Requests.php');
require_once './vendor/autoload.php';
fputs (STDERR,"*** 開始 ***\n");
Requests::register_autoloader();
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$client_id = getenv("CLIENT_ID");
$client_secret = getenv("CLIENT_SECRET");
$url_base = getenv("DEVELOPER_API_BASE_URL");
$url_publish = getenv("ACCESS_TOKEN_PUBLISH_URL");
$data = array('grantType' => 'client_credentials','clientId' => $client_id,
'clientSecret' => $client_secret);
$str_json = json_encode ($data);
$headers = array('Content-Type' => 'application/json');
$request = Requests::post($url_publish, $headers, $str_json);
var_dump($request->status_code);
print("-----------\n");
var_dump($request->body);
print("-----------\n");
$json_string = $request->body;
$dict_aa = json_decode ($json_string,true);
print($dict_aa["access_token"] . "\n");
fputs (STDERR,"*** 終了 ***\n");
// ------------------------------------------------------------------
?>
実行結果
$ ./acess_token.php
*** 開始 ***
int(201)
-----------
string(249) "
{
"access_token": "7Zj26srl557J3ffR********",
"token_type": "bearer",
"expires_in": "86399" ,
"scope": "" ,
"issued_at": "1582683782964"
}
"
-----------
7Zj26srl557J3ffRGfbdWYAbCT8U
*** 終了 ***