googleworkspace / php-samples

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

Error: refresh token must be passed in or set as part of setAccessToken #16

Closed rbaenar closed 6 years ago

rbaenar commented 6 years ago

He utilizado el ejemplo de quickstart.php para Google Calendar y funciona todo correcto hasta que pasan algo más de dos horas y me devuelve un error al intentar refrescar el token al expirar.

He mirado en muchos foros y no funciona nada de lo que se indica.

Por favor, me puede ayudar.

Sample:

ERROR

`PHP Fatal error: Uncaught LogicException: refresh token must be passed in or set as part of setAccessToken in C:\www\medel\pru\vendor\google\apiclient\src\Google\Client.php:258 Stack trace:

0 C:\www\medel\pru\quickstart.php(51): Google_Client->fetchAccessTokenWithRefreshToken(NULL)

1 C:\www\medel\pru\quickstart.php(59): getClient()

2 {main}

thrown in C:\www\medel\pru\vendor\google\apiclient\src\Google\Client.php on line 258

Fatal error: Uncaught LogicException: refresh token must be passed in or set as part of setAccessToken in C:\www\medel\pru\vendor\google\apiclient\src\Google\Client.php:258 Stack trace:

0 C:\www\medel\pru\quickstart.php(51): Google_Client->fetchAccessTokenWithRefreshToken(NULL)

1 C:\www\medel\pru\quickstart.php(59): getClient()

2 {main}

thrown in C:\www\medel\pru\vendor\google\apiclient\src\Google\Client.php on line 258`

Actual Behavior

Steps to Reproduce the Problem

1.He seguido los pasos que se indican en la guía de Google (https://developers.google.com/calendar/quickstart/php)

Specifications

erickoledadevrel commented 6 years ago

This error is being thrown because the saved tokens in token.json doesn't contain a refresh_token, which is needed to refresh the access token after it's expired. At the moment the code isn't checking that a refresh token exists before it attempts to refresh the access token, nor handling the case when one doesn't exist. I'll put together a PR to fix this.

syedmuhd82 commented 6 years ago

The code from the developer contain a bug to handle the refreshtoken as today 9 September 2018. i already fix the solution for this... you must save 2 location for token

  1. handlerefeshtoken.json
  2. token.json

hope this help...

ghost commented 6 years ago

How long can you solve this problem?

syedmuhd82 commented 6 years ago

Almost 2 day and 2 night to figured it out :( the example on the quickstart is not good example.. because as google developer, the dev should test before put at the website as example.. now many newbie cannot start with quickstart hehe...

ghost commented 6 years ago

😂😂😂 I'm looking forward about that. Because I'm a newbie so impatient to do something that is my first small project...😁😁

Đăng Nam

Vào 16:31, T.3, 11 Th9, 2018 Syed Muhammad Bin Syed Hussin < notifications@github.com> đã viết:

Almost 2 day and 2 night to figured it out :( the example on the quickstart is not good example.. because as google developer, the dev should test before put at the website as example.. now many newbie cannot start with quickstart hehe...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/gsuitedevs/php-samples/issues/16#issuecomment-420209877, or mute the thread https://github.com/notifications/unsubscribe-auth/AkkcEF1zHvu_bgLyrR-WEO949Hdh1aMTks5uZ4L1gaJpZM4VtuOU .

erickoledadevrel commented 6 years ago

I pushed out some new code that handles this case better. Please try that new code and let me know if you still have a problem.

ghost commented 5 years ago

is it auto refresh-token for my apps or I have to copy the authenication from the warn on the CMD?

ghost commented 5 years ago

if I wanna auto the refresh-token, do I need some file to get that?

syedmuhd82 commented 5 years ago

Hyperaktiv, do u already test the code? Suppose the code from eric now it will auto refresh the new token when reach after 3600 second..

ghost commented 5 years ago

ah, my fault, I've not read carefully.. Sorry Thank you very much. Hope that I can keep in touch with you

syedmuhd82 commented 5 years ago

No problem.. hope u can test the eric way, if any problem u can roger here, eric will fix the bug...