简体   繁体   English

在Javascript中对Google SpreadSheet API使用令牌访问

[英]Using token access for Google SpreadSheet API in Javascript

The question is simple. 问题很简单。 I got the access_token by Oauth 2. and I want to access spreadsheet on google to read. 我获得了Oauth 2的access_token,我想访问Google上的电子表格以进行阅读。 But When I read api from https://developers.google.com/sheets/ . 但是当我从https://developers.google.com/sheets/阅读api时。 I don't get where to put access_token or do i even need it. 我不知道将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; 我试图把我的accessToken上的网址和失败。对于实例: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. 它说“ {”数据“:{”错误“:{”代码“:403,”消息“:”该请求无法与客户端项目一起识别。 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. 请通过请求传递有效的API密钥。“,”状态“:” PERMISSION_DENIED“}},”状态“:403,”配置“:{”方法“:” 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”:“”}“我知道我必须以某种方式附加访问令牌,但是我不知道如何。 Do you guy have any idea for the spreadsheet api? 你们对电子表格api有任何想法吗?

Thank you for reading this 谢谢您阅读此篇

I am not familiar with the ionic-framework, but to use the access token, you should either add that into the HTTP headers (eg Authorization: Bearer ya29.xxxxxxxxxxxxxxxxxx ) or include that in your query string, 我对ionic-framework并不熟悉,但是要使用访问令牌,您应该将其添加到HTTP标头中(例如Authorization: Bearer ya29.xxxxxxxxxxxxxxxxxx ),或者将其包含在查询字符串中,

Ref: https://developers.google.com/identity/protocols/OAuth2InstalledApp#callinganapi 参考: 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;

I had a same requirement of accessing the google spreadsheet from the ionic cellphone, and we have used tabletop.js. 我对从离子手机访问google电子表格有相同的要求,并且我们使用了tabletop.js。 Using this we were able to read the spreadsheet completely. 使用此工具,我们可以完全读取电子表格。 Try this if it helps you anyway. 如果仍然有帮助,请尝试此操作。 https://github.com/jsoma/tabletop https://github.com/jsoma/tabletop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 javascript 刷新谷歌日历 api 的访问令牌(反应) - refresh access token for google calendar api using javascript (react) Javascript访问Google电子表格 - Javascript access google spreadsheet 在JavaScript中访问Google Drive电子表格 - Access google drive spreadsheet in javascript 使用 Javascript API 检索访问令牌 - Retrieve Access Token Using Javascript API 如何使用Google表格API + Javascript更新电子表格 - How to update spreadsheet using Google Sheets API + Javascript 如何使用一个OAuth令牌通过JavaScript API访问Google Analytics(分析)? - How to access Google Analytics through the JavaScript API with one OAuth token? Google+ API不会返回access_token Javascript - Google+ API doesnt return access_token Javascript Google Javascript API:访问令牌过期后会发生什么? - Google Javascript API: What happen after access token expire? 带有Simple Access API密钥的Google Execution API可以访问AUTHORS电子表格吗? - Google Execution API with Simple Access API key to access AUTHORS spreadsheet? 如何使用Google表格API在JavaScript中创建包含两个表格的Google电子表格? - How Can I create a Google spreadsheet with two sheets in javascript using Google sheets API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM