如何解决使用Google的Node.js Sheets API时身份验证错误:提供的密钥文件未定义有效的重定向URI 您需要一个有效重定向URI
我正在尝试使用Node.js Google Sheets API写入google工作表,但是当我运行脚本时,使用下面引号引起的命令,出现以下错误:
节点append.js 电子表格ID 0
Error: The provided keyfile does not define a valid
redirect URI. There must be at least one redirect URI defined,and this sample
assumes it redirects to 'http://localhost:3000/oauth2callback'. Please edit
your keyfile,and add a 'redirect_uris' section. For example:
"redirect_uris": [
"http://localhost:3000/oauth2callback"
]
at authenticate (/folder/node_modules/@google-cloud/local-auth/build/src/index.js:56:15)
at runSample (/folder/append.js:24:22)
at Object.<anonymous> (/folder/append.js:52:3)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
我正在使用Google在其googleapis Github repository中提供的append.js脚本。
我的oauth2.keys.json文件:
{
"web": {
"client_id": "my-client-id.apps.googleusercontent.com","project_id": "my-id","auth_uri": "https://accounts.google.com/o/oauth2/auth","token_uri": "https://oauth2.googleapis.com/token","auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs","client_secret": "client_secret","redirect_uris": [
"https://my-site.net"
]
}
}
解决方法
您需要一个有效重定向URI
我知道,这就是错误的意思,很抱歉重复一遍,但是,这是您被绊倒的线索。
成功授权应用程序后,重定向URI不能只是"https://my-site.net"
。 URI上的资源必须能够处理OAuth2响应,该响应将包含授权码或错误响应。
Here是指向Google指南的链接,用于处理服务器响应。
Here是Github Repo的一个问题,与之相关,因为这是对与您有类似问题的人的一个很好的案例研究,可以在您确定如何验证应用程序时为您提供帮助。
Google提供的Oauth2 docs具有广泛的信息和帮助指南。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。