Misoca APIを用いた開発を行っているのですが、Ouath2.0の設定でつまづいております。
下記を参照に開発しております。
http://zero-one-x.com/archives/223
composerはインストールしており、下記コマンドでファイルのダウンロードも行っております。
linux
1composer 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
1<?php 2$provider = new \League\OAuth2\Client\Provider\GenericProvider([ 3 'clientId' => 'clientId', // The client ID assigned to you by the provider 4 'clientSecret' => 'clientSecret', // The client password assigned to you by the provider 5 'redirectUri' => 'https://sample-program.xyz/WebAPI2/api.php', 6 'urlAuthorize' => 'https://app.misoca.jp/oauth2/authorize', 7 'urlAccessToken' => 'https://app.misoca.jp/oauth2/token', 8 'urlResourceOwnerDetails' => '', 9 'scopes'=>'write' 10]); 11 12// If we don't have an authorization code then get one 13if (!isset($_GET['code'])) { 14 // Fetch the authorization URL from the provider; this returns the 15 // urlAuthorize option and generates and applies any necessary parameters 16 // (e.g. state). 17 $authorizationUrl = $provider->getAuthorizationUrl(); 18 19 // Get the state generated for you and store it to the session. 20 $_SESSION['oauth2state'] = $provider->getState(); 21 22 // Redirect the user to the authorization URL. 23 header('Location: ' . $authorizationUrl); 24 exit; 25 26// Check given state against previously stored one to mitigate CSRF attack 27} elseif (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && $_GET['state'] !== $_SESSION['oauth2state'])) { 28 29 if (isset($_SESSION['oauth2state'])) { 30 unset($_SESSION['oauth2state']); 31 } 32 33 exit('Invalid state'); 34 35} else { 36 try { 37 // Try to get an access token using the authorization code grant. 38 $accessToken = $provider->getAccessToken('authorization_code', [ 39 'code' => $_GET['code'] 40 ]); 41 42 // APIにリクエストを送信(見積もりの作成) 43 // $mitsumoriに見積もりの配列を入れます。詳細はMisocaのドキュメントを確認 44 $request = $provider->getAuthenticatedRequest( 45 'POST', 46 'https://app.misoca.jp/api/v3/estimate', 47 $accessToken, 48 array( 49 "body"=>json_encode($mitsumori), 50 'headers' => array( 51 'Content-Type' => 'application/json;charset=UTF-8', // このヘッダーがないと返りがうまくいかない 52 ), 53 ) 54 ); 55 56 // APIからのレスポンスを取得 57 $response = $provider->getResponse($request); 58 // レスポンスのボディ部分を取得 59 $data = $response->getBody()->getContents(); 60 61 // JSONで返ってきているのでデコード 62 $result = json_decode($data, true); 63 64 session_destroy();// セッションを削除 65 66 } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) { 67 68 // Failed to get the access token or user details. 69 exit($e->getMessage()); 70 71 } 72 73}
■ エラー 内容
php
1Fatal 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
知識不足で大変恐縮ですが、アドバイスいただけると幸いです。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。