Misoca APIを用いた開発を行っているのですが、Ouath2.0の設定でつまづいております。
下記を参照に開発しております。
http://zero-one-x.com/archives/223
composerはインストールしており、下記コマンドでファイルのダウンロードも行っております。
linux
composer require league/oauth2-client
■ 対象ドメイン
http://sample-program.xyz/WebAPI2/
■ 階層
/sample-program.xyz/public_html/WebAPI2/
/sample-program.xyz/public_html/WebAPI2/index.php
/sample-program.xyz/public_html/WebAPI2/api.php
/sample-program.xyz/public_html/WebAPI2/oauth/composer.json
/sample-program.xyz/public_html/WebAPI2/oauth/composer.lock
/sample-program.xyz/public_html/WebAPI2/oauth/vendor/
/sample-program.xyz/public_html/WebAPI2/oauth/vendor/autoload.php
/sample-program.xyz/public_html/WebAPI2/oauth/vendor/composer/(以下省略)
/sample-program.xyz/public_html/WebAPI2/oauth/vendor/guzzlehttp/(以下省略)
/sample-program.xyz/public_html/WebAPI2/oauth/vendor/league/(以下省略)
/sample-program.xyz/public_html/WebAPI2/oauth/vendor/paragonie/(以下省略)
/sample-program.xyz/public_html/WebAPI2/oauth/vendor/psr/(以下省略)
/sample-program.xyz/public_html/WebAPI2/oauth/vendor/ralouphie/(以下省略)
■ コールバックURL
https://sample-program.xyz/WebAPI2/index.php
■ コード記述
http://sample-program.xyz/WebAPI2/api.php
php
<?php $provider = new \League\OAuth2\Client\Provider\GenericProvider([ 'clientId' => 'clientId', // The client ID assigned to you by the provider 'clientSecret' => 'clientSecret', // The client password assigned to you by the provider 'redirectUri' => 'https://sample-program.xyz/WebAPI2/api.php', 'urlAuthorize' => 'https://app.misoca.jp/oauth2/authorize', 'urlAccessToken' => 'https://app.misoca.jp/oauth2/token', 'urlResourceOwnerDetails' => '', 'scopes'=>'write' ]); // If we don't have an authorization code then get one if (!isset($_GET['code'])) { // Fetch the authorization URL from the provider; this returns the // urlAuthorize option and generates and applies any necessary parameters // (e.g. state). $authorizationUrl = $provider->getAuthorizationUrl(); // Get the state generated for you and store it to the session. $_SESSION['oauth2state'] = $provider->getState(); // Redirect the user to the authorization URL. header('Location: ' . $authorizationUrl); exit; // Check given state against previously stored one to mitigate CSRF attack } elseif (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && $_GET['state'] !== $_SESSION['oauth2state'])) { if (isset($_SESSION['oauth2state'])) { unset($_SESSION['oauth2state']); } exit('Invalid state'); } else { try { // Try to get an access token using the authorization code grant. $accessToken = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'] ]); // APIにリクエストを送信(見積もりの作成) // $mitsumoriに見積もりの配列を入れます。詳細はMisocaのドキュメントを確認 $request = $provider->getAuthenticatedRequest( 'POST', 'https://app.misoca.jp/api/v3/estimate', $accessToken, array( "body"=>json_encode($mitsumori), 'headers' => array( 'Content-Type' => 'application/json;charset=UTF-8', // このヘッダーがないと返りがうまくいかない ), ) ); // APIからのレスポンスを取得 $response = $provider->getResponse($request); // レスポンスのボディ部分を取得 $data = $response->getBody()->getContents(); // JSONで返ってきているのでデコード $result = json_decode($data, true); session_destroy();// セッションを削除 } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) { // Failed to get the access token or user details. exit($e->getMessage()); } }
■ エラー 内容
php
Fatal error: Uncaught Error: Class 'League\OAuth2\Client\Provider\GenericProvider' not found in /home/ofp/sample-program.xyz/public_html/WebAPI2/api.php:2 Stack trace: #0 {main} thrown in /home/ofp/sample-program.xyz/public_html/WebAPI2/api.php on line 2
知識不足で大変恐縮ですが、アドバイスいただけると幸いです。
まだ回答がついていません
会員登録して回答してみよう