简体   繁体   中英

GMail Add-On / Apps script can't connect to Google Cloud SQL - permission to call getCloudSqlConnection

I'm writing a simple add-on that will get sender's data for each message from our DB. GMail add-on gets the message-id and queries our DB for additional data about the client to show it to the user.

I've followed CloudSQL tutorial, for MySQL and Postgres and in the simpliest scenario I'm getting this error

You do not have permission to call getCloudSqlConnection

while I'm trying to connect to GCP Cloud SQL. No problem to connect from outside with external client, etc. though.

The code is as follows

var conn = Jdbc.getCloudSqlConnection("jdbc:google:mysql://[my-project-and-instance-id]/[my-db-name]", [user], [password]);

My script is attached to the same project as the database.

An internet search for "You do not have permission to call getCloudSqlConnection" gives an empty result.

Including " https://www.googleapis.com/auth/sqlservice " to "oauthScopes" in my manifest file fixed the error for me.

Updated scopes:

"oauthScopes": ["https://www.googleapis.com/auth/gmail.addons.execute","https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/sqlservice", "https://www.googleapis.com/auth/sqlservice.admin", "https://www.googleapis.com/auth/gmail.readonly", "https://www.googleapis.com/auth/script.external_request", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/gmail.addons.current.action.compose"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM