I'm trying to extract a short data from Google Sheet, the flow is as follow;
我正试图从Google Sheet中提取一个简短的数据,流程如下;
- Authorizing the user (access type: offline)
- 授权用户(访问类型:离线)
- Storing/caching the token per the oAuth2 flow.
- 根据oAuth2流存储/缓存令牌。
- Loading the cached token and use it to extract the data.
- 加载缓存的令牌并使用它来提取数据。
But once I uploaded on the server, the returned result become inconsistent.
但是一旦我上传到服务器上,返回的结果就会变得不一致。
I don't know what causing it because most of the time it returns the right data, and it works perfectly on my local.
我不知道是什么导致它,因为大多数时候它返回正确的数据,它在我的本地完美地工作。
Error Message;
错误信息;
Google sheet API read: Error: The request is missing a valid API key.
Server Information: Google App Engine, trial version;
服务器信息:Google App Engine,试用版;
runtime: nodejs
env: flex
The node.js code is below;
node.js代码如下;
getUser(id) {
this.sheets.spreadsheets.values.get({
auth: this.oauth2Client,
spreadsheetId: id,
range: 'Sheet1!A1:E'
}, (err, response) => {
if(err) {
this.reject({
status: 0,
message: "Google sheet API read: " + err
});
return;
}
// The rest is omitted.
})
}
You can try the test request here (I haven't added any security measure for debugging purposes);
您可以在此处尝试测试请求(我没有为调试目的添加任何安全措施);
https://deep-contact-179901.appspot.com/v1/google/users
https://deep-contact-179901.appspot.com/v1/google/users
1 个解决方案
#1
0
Based from this thread, all Google APIs require that you create a project on Google Developer Console and identify yourself and your application, even to access public data. Go to Google Developer Console and create a public api key. Remember to activate the Google Sheets API. Then just add key=[YourKey]
as a parameter on your request.
根据此主题,所有Google API都要求您在Google Developer Console上创建项目,并识别您自己和您的应用程序,甚至是访问公共数据。转到Google Developer Console并创建公共API密钥。请务必激活Google表格API。然后只需在您的请求中添加key = [YourKey]作为参数。
Google sheet API read: Error: The request is missing a valid API key.
Means that you have not identified yourself to Google. In 2015 Google Start to require that we identify ourselves you cant just use a Google API without telling google who you are. You do that by creating a project on Google developer console. Create an API key and use that API key in all of your requests. This only works with Public data.
意味着您尚未向Google表明自己的身份。在2015年Google Start要求我们确定您自己不能使用Google API而不告诉谷歌您是谁。您可以通过在Google开发人员控制台上创建项目来实现。创建API密钥并在所有请求中使用该API密钥。这仅适用于公共数据。
Note: With private user data you would need to use OAuth and use either access_token=your token or set the header
注意:对于私人用户数据,您需要使用OAuth并使用access_token =您的令牌或设置标头
An access token is not the same as a API Key.
访问令牌与API密钥不同。
Hope this helps!
希望这可以帮助!
#1
0
Based from this thread, all Google APIs require that you create a project on Google Developer Console and identify yourself and your application, even to access public data. Go to Google Developer Console and create a public api key. Remember to activate the Google Sheets API. Then just add key=[YourKey]
as a parameter on your request.
根据此主题,所有Google API都要求您在Google Developer Console上创建项目,并识别您自己和您的应用程序,甚至是访问公共数据。转到Google Developer Console并创建公共API密钥。请务必激活Google表格API。然后只需在您的请求中添加key = [YourKey]作为参数。
Google sheet API read: Error: The request is missing a valid API key.
Means that you have not identified yourself to Google. In 2015 Google Start to require that we identify ourselves you cant just use a Google API without telling google who you are. You do that by creating a project on Google developer console. Create an API key and use that API key in all of your requests. This only works with Public data.
意味着您尚未向Google表明自己的身份。在2015年Google Start要求我们确定您自己不能使用Google API而不告诉谷歌您是谁。您可以通过在Google开发人员控制台上创建项目来实现。创建API密钥并在所有请求中使用该API密钥。这仅适用于公共数据。
Note: With private user data you would need to use OAuth and use either access_token=your token or set the header
注意:对于私人用户数据,您需要使用OAuth并使用access_token =您的令牌或设置标头
An access token is not the same as a API Key.
访问令牌与API密钥不同。
Hope this helps!
希望这可以帮助!