在Javascript中使用Google SpreadSheet API的令牌访问权限

时间:2022-05-01 22:58:53

The question is simple. I got the access_token by Oauth 2. and I want to access spreadsheet on google to read. But When I read api from https://developers.google.com/sheets/ . I don't get where to put access_token or do i even need it.

问题很简单。我得到了Oauth 2的access_token。我想在google*问电子表格来阅读。但是,当我从https://developers.google.com/sheets/上阅读api时。我没有把access_token放到哪里,或者甚至不需要它。

I tried to put my access-token on url and failed.. for instance: var sample_url = "https://spreadsheets.google.com/pub?key=0Ago31FFWG3xZrdHF2bWNjcTJFLXJ6UUHYT3dEakdEaXc&hl=en&output=html?accesstoken=" + accesstoken; I got the response back. it says "{"data":{"error":{"code":403,"message":"The request cannot be identified with a client project. Please pass a valid API key with the request.","status":"PERMISSION_DENIED"}},"status":403,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"https://sheets.googleapis.com/v4/spreadsheets/1ZduILENRVcnzXTynV00j9puWJEvGgz-EcxOgoPRpOGI/values/A1:D3?ya29.Ci87A42OTqtIqXylTU7QxZALwJjRuf_oXf2FJ-MTY7QvXgWzPhZEKhi4Yhn7HVVV7g","headers":{"Accept":"application/json, text/plain, /"}},"statusText":""}" I know I have to attach the access-token somehow, but i don't know how. Do you guy have any idea for the spreadsheet api?

我试图把我的accessToken上的网址和失败。对于实例:var SAMPLE_URL =“https://spreadsheets.google.com/pub?key=0Ago31FFWG3xZrdHF2bWNjcTJFLXJ6UUHYT3dEakdEaXc&hl=en&output=html?accesstoken=” +的accessToken;我得到了回复。它说“{”data“:{”error“:{”code“:403,”message“:”无法使用客户端项目识别请求。请通过请求传递有效的API密钥。“,”status“:”PERMISSION_DENIED“}},”status“:403,”config“:{”method“:”GET“,”transformRequest“:[null],” transformResponse “:[空],” URL “:” https://sheets.googleapis.com/v4/spreadsheets/1ZduILENRVcnzXTynV00j9puWJEvGgz-EcxOgoPRpOGI/values/A1:D3?ya29.Ci87A42OTqtIqXylTU7QxZALwJjRuf_oXf2FJ-MTY7QvXgWzPhZEKhi4Yhn7HVVV7g “ ”头“:{” 接受“:”application / json,text / plain,/“}},”statusText“:”“}”我知道我必须以某种方式附加访问令牌,但我不知道如何。你对电子表格api有什么想法吗?

Thank you for reading this

谢谢您阅读此篇

2 个解决方案

#1


0  

I am not familiar with the ionic-framework, but to use the access token, you should either add that into the HTTP headers (e.g. Authorization: Bearer ya29.xxxxxxxxxxxxxxxxxx) or include that in your query string,

我不熟悉离子框架,但要使用访问令牌,您应该将其添加到HTTP标头中(例如授权:Bearer ya29.xxxxxxxxxxxxxxxxxx)或将其包含在您的查询字符串中,

Ref: https://developers.google.com/identity/protocols/OAuth2InstalledApp#callinganapi


There is a mistake in your sample_url, it should be &access_token= instead of ?accesstoken=

你的sample_url中有一个错误,它应该是&access_token =而不是?accesstoken =

It should be,

它应该是,

var sample_url = "https://spreadsheets.google.com/pub"
               + "?key=0Ago31FFWG3xZrdHF2bWNjcTJFLXJ6UUHYT3dEakdEaXc"
               + "&hl=en&output=html&access_token=" + accesstoken;

#2


0  

I had a same requirement of accessing the google spreadsheet from the ionic cellphone, and we have used tabletop.js. Using this we were able to read the spreadsheet completely. Try this if it helps you anyway. https://github.com/jsoma/tabletop

我有同样的要求从离子手机访问谷歌电子表格,我们使用tabletop.js。使用此功能,我们可以完全阅读电子表格。无论如何它试试这个。 https://github.com/jsoma/tabletop

#1


0  

I am not familiar with the ionic-framework, but to use the access token, you should either add that into the HTTP headers (e.g. Authorization: Bearer ya29.xxxxxxxxxxxxxxxxxx) or include that in your query string,

我不熟悉离子框架,但要使用访问令牌,您应该将其添加到HTTP标头中(例如授权:Bearer ya29.xxxxxxxxxxxxxxxxxx)或将其包含在您的查询字符串中,

Ref: https://developers.google.com/identity/protocols/OAuth2InstalledApp#callinganapi


There is a mistake in your sample_url, it should be &access_token= instead of ?accesstoken=

你的sample_url中有一个错误,它应该是&access_token =而不是?accesstoken =

It should be,

它应该是,

var sample_url = "https://spreadsheets.google.com/pub"
               + "?key=0Ago31FFWG3xZrdHF2bWNjcTJFLXJ6UUHYT3dEakdEaXc"
               + "&hl=en&output=html&access_token=" + accesstoken;

#2


0  

I had a same requirement of accessing the google spreadsheet from the ionic cellphone, and we have used tabletop.js. Using this we were able to read the spreadsheet completely. Try this if it helps you anyway. https://github.com/jsoma/tabletop

我有同样的要求从离子手机访问谷歌电子表格,我们使用tabletop.js。使用此功能,我们可以完全阅读电子表格。无论如何它试试这个。 https://github.com/jsoma/tabletop