googleworkspace / php-samples

PHP samples for Google Workspace APIs
Apache License 2.0
288 stars 348 forks source link

PHP Google Calendar Api #31

Closed ANJUJOJER closed 5 years ago

ANJUJOJER commented 5 years ago

I worked on php google calendar api and i find an issue on token generation

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'invalid json token' in E:\xampp\htdocs\test\admin\calendar\quickstart\vendor\google\apiclient\src\Google\Client.php:428 Stack trace: #0 E:\xampp\htdocs\test\admin\calendar\quickstart\quickstart.php(29): Google_Client->setAccessToken(NULL) #1 E:\xampp\htdocs\test\admin\calendar\quickstart\quickstart.php(68): getClient() #2 {main} thrown in E:\xampp\htdocs\test\admin\calendar\quickstart\vendor\google\apiclient\src\Google\Client.php on line 428 token.json is not generated automatically

zehra101 commented 5 years ago

you need to store the access token bundle in session ** Try this $client = new Google_Client(); $client->setAuthConfig('Your json config file'); $client->setRedirectUri("your authenticated redirect url"); $client->addScope(Google_Service_Calendar::CALENDAR); $this->client = $client;

** then in method u can get access_token through session.

      session_start();
    if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {

        $this->client->setAccessToken($_SESSION['access_token']);

        $service = new Google_Service_Calendar($this->client);

    }
erickoledadevrel commented 5 years ago

As mentioned in the quickstart instructions, this quickstart is designed to be run on the command line.