2016-10-12 21 views
2

私があなたを助けてくれることを願っています。GoogleカレンダーAPI、クラスGoogle_Service

Oauth2認証を使用してGoogle(カレンダー)APIに接続しようとしています。

私はこれらの手順に従っている。このため

:コンポーザーを使用して

  • 登録アプリのGoogleの開発者コンソールから
  • インストールされたクライアントライブラリ(グーグル-API-PHP-クライアント)
  • ベンダーに以下のスクリプトを置きましたフォルダ:
 

    require_once 'autoload.php'; 
    require('google/apiclient-services/src/Google/Service/Oauth2.php'); 
    session_start(); 

    // ******************************************************** // 
    // Get these values from https://console.developers.google.com 
    // Be sure to enable the Analytics API 
    // ******************************************************** // 
    $client_id = 'myclientid'; 
    $client_secret = 'myclientsecret'; 
    $redirect_uri = 'https://domain.nl/dev/vendor/google/apiclient-services/src/Google/Service/Oauth2.php'; //identical as in Google console 

    $client = new Google_Client(); 
    $client->setApplicationName("Client_Library_Examples"); 
    $client->setClientId($client_id); 
    $client->setClientSecret($client_secret); 
    $client->setRedirectUri($redirect_uri); 
    $client->setAccessType('offline'); // Gets us our refreshtoken 

    $client->setScopes(array('https://www.googleapis.com/auth/calendar.readonly')); 


    //For loging out. 
    if (isset($_GET['logout'])) { 
     unset($_SESSION['token']); 
    } 


    // Step 2: The user accepted your access now you need to exchange it. 
    if (isset($_GET['code'])) { 

    $client->authenticate($_GET['code']); 
    $_SESSION['token'] = $client->getAccessToken(); 
    $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 
    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); 
    } 

    // Step 1: The user has not authenticated we give them a link to login  
    if (!isset($_SESSION['token'])) { 

    $authUrl = $client->createAuthUrl(); 

    print "Connect Me!"; 
    }  


    // Step 3: We have access we can now create our service 
    if (isset($_SESSION['token'])) { 
    $client->setAccessToken($_SESSION['token']); 
    print "LogOut
"; $service = new Google_Service_Calendar($client); $calendarList = $service->calendarList->listCalendarList();; while(true) { foreach ($calendarList->getItems() as $calendarListEntry) { echo $calendarListEntry->getSummary()."
\n"; // get events $events = $service->events->listEvents($calendarListEntry->id); foreach ($events->getItems() as $event) { echo "-----".$event->getSummary()."
"; } } $pageToken = $calendarList->getNextPageToken(); if ($pageToken) { $optParams = array('pageToken' => $pageToken); $calendarList = $service->calendarList->listCalendarList($optParams); } else { break; } } }


アン幸い私は、右のAuthenticationのために、「受け入れる」ボタンをクリックした後、エラーを取得しています:

 
Fatal error: Class 'Google_Service' not found in /home/user/domains/domain.nl/private_html/dev/vendor/google/apiclient-services/src/Google/Service/Oauth2.php on line 32 

Google research

は、これまで助けにはなりませんでした。

考えられる解決策:正しく

  • 設定自動ロードパス。 チェック

     
    require_once 'autoload.php'; 
    
  • サポートされているPHPバージョンを実行します。 (5.6 + 7.1を試しました)をチェックしてください。

  • composer.jsonのライブラリと、実際に自動ロードされているライブラリとの間に何か違うものがあるかどうかを確認してください。 チェック

ご協力ありがとうございます。

答えて

0

更新:これは修正されました。私は私のスクリプトに戻るのではなく、私のredirect_urlとしてOauth2.phpを使いました。初心者の間違い:

関連する問題