gmail-tester
gmail-tester copied to clipboard
Token expire after 7 days
How to automatically update the token in gmail API.
I'm with the same issue, of course I know about the function refresh-token that @levz0r created, but even using that function returns me an error "invalid_grant", if you could give us a complete example on how to use refresh-token would be great @levz0r
thank you in advanced
I have the same problem and API for the refresh token doesn't work
Yeah I have the same problem. Not sure how long it's lasting exactly but the refresh_access_token function is not working.
@muhammadmubeen12345 @damasofc @pakhilov
Did any of you find a solution / workaround in the end?
@LordA98 I have not found any solution about update of token automatically. Every Monday I update the token manually...
Hey @LordA98 and @muhammadmubeen12345 have you both tried "refresh_access_token"?
I just added to my cypress project easily with this file: refreshGmailToken.ts.
I then call this script on each CI run uploading the new token to S3 here: github workflow!
This will be downloaded by the following runs!
I hope I was able to help you and if you need more help just let me know! If I helped you can star my repository here where I test all sort of stuff with cypress, gmail and more: https://github.com/riccardogiorato/cypress-for-everything
Hey @LordA98 and @muhammadmubeen12345 have you both tried "refresh_access_token"?
I just added to my cypress project easily with this file: refreshGmailToken.ts.
I then call this script on each CI run uploading the new token to S3 here: github workflow!
This will be downloaded by the following runs!
I hope I was able to help you and if you need more help just let me know! If I helped you can star my repository here where I test all sort of stuff with cypress, gmail and more: https://github.com/riccardogiorato/cypress-for-everything
Yes, even after using the refresh_access_token function, the 'invalid_grant' error will eventually show up.
@the-bmc-dev can it be because you are scanning the inbox too frequently of using broad filters?
@levz0r I did not think about that, are there such restrictions on Gmail API? Edit: I've checked the quotas and none of them were reached.
Hi,
I created this in plugins/index.js
on("task", { "gmail:refresh_access_token": async () => { const token = await gmail_tester.refresh_access_token( path.resolve(__dirname, "credentials.json"), path.resolve(__dirname, "token.json") ); console.log("Refreshed the gmail token!"); return token; }, });
and I call it like this in my test:
cy.task("gmail:refresh_access_token");
I am getting this error:
`cy.task('gmail:refresh_access_token') failed with the following error:
> No refresh token is set.`
Any idea where do I make mistake?
Hi, I created this in plugins/index.js
on("task", { "gmail:refresh_access_token": async () => { const token = await gmail_tester.refresh_access_token( path.resolve(__dirname, "credentials.json"), path.resolve(__dirname, "token.json") ); console.log("Refreshed the gmail token!"); return token; }, });
and I call it like this in my test:
cy.task("gmail:refresh_access_token");
I am getting this error:
`cy.task('gmail:refresh_access_token') failed with the following error: > No refresh token is set.`
Any idea where do I make mistake?
Thanks for the code example. I too would love to hear how others are using it, otherwise without a fully working refresh token they expire every two days so the whole plugin becomes not very useful.
Hey folks,
I find the solution.
First of all, do not forget to add "refresh_token":"Your token" to your token.json!!!
After that index.js:
It's ready to test: cy.task("gmail:refresh_access_token", {});
Have fun!
Hey folks,
I find the solution.
First of all, do not forget to add "refresh_token":"Your token" to your token.json!!! After that index.js:
It's ready to test: cy.task("gmail:refresh_access_token", {});
Have fun!
Unfortunately this didn't seem to help at all, it just says 'invalid_grant' when running the refresh_token task now. e.g. CypressError: cy.task('gmail:refresh_access_token')
failed with the following error:
invalid_grant
Hi, I'm using the refress_access_token function but it requires to open a url and the copy again the code. Is there any way to avoid this?
Hey folks,
I find the solution.
First of all, do not forget to add "refresh_token":"Your token" to your token.json!!! After that index.js:
It's ready to test: cy.task("gmail:refresh_access_token", {});
Have fun!
@omersomuncu Check this issue. The key refresh_token
should be set, check your applicationtype-setting for the client -> should be Desktop app
@levz0r could you please help to resolve this issue?
would be nice to have this done automatically also, the above solutions only work if you save token.json file to disk
Hi @omersomuncu im trying to solution i don't have a CI/CD pipeline. I am just executing the test from terminal. How can i automatically refresh the token? Please can anyone support ? @Revadike @taninnazar @levz0r
@mariamaslam there is nothing to do with a code. To have a stable token you need to change the Publishing status of your Google app from "In testing" to "In production". You can do it here - https://console.cloud.google.com/apis/credentials/consent
Hi @taninnazar thank you quick response, so once changed to "in production" the token will not expire right?
Hi @mariamaslam , the token will expire but more rarely - like once a year or once a half year
Amazinggg @taninnazar do i just need to change the permission n that would be it or do i need to re- generate the token with gmail-tester?