Google工作表API验证流程未提供验证码

Google Sheets API verification flow does not provide a verification code

根据 this article,我应该启用 Google 工作表 API(完成),将代码块复制并粘贴到文件 quickstart.php 中,然后在终端上打开服务器 运行

$ php quickstart.php

然后提示:

$ php quickstart.php 
Open the following link in your browser:
https://accounts.google.com/o/oauth2/auth?response_type=code&access_type=offline&client_id=<something>.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Fmy.website.com%2F&state&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets.readonly&prompt=select_account%20consent
Enter verification code: 

所以我在浏览器中打开 link,接受 my.website.com 访问我的工作表,然后我被重定向到 my.website.com 的首页。

那么我输入什么作为验证码?

对于您的情况,请检查浏览器中重定向页面的URL。当你看到 URL 时,在你的情况下,我认为你可以看到以下 URL.

http://my.website.com/?code=#####&scope=https://www.googleapis.com/auth/spreadsheets.readonly

在这种情况下,代码是 code=##########,这是查询参数。请复制代码并将其放入 运行 $ php quickstart.php 终端的 Enter verification code:。这样,创建了 $tokenPath = 'token.json';token.json,包括访问令牌和刷新令牌。此后,当您 运行 $ php quickstart.php 时,脚本会使用刷新令牌检索到的访问令牌。这样,不需要授权过程。关于refresh token过期,请查看the official document.

参考: