[英]How to create a new google spreadsheet through an app in react native?
I am writing a simple app in which I would like to create a google spreadsheet when the user wants to.我正在编写一个简单的应用程序,我想在用户想要的时候创建一个谷歌电子表格。 I could only get to the part below, where I can read data from already existing google spreadsheets, but I'm not able to convert this such that, at the click of the button, I will be able to create a new google spreadsheet.我只能进入下面的部分,在那里我可以从现有的谷歌电子表格中读取数据,但我无法将其转换为这样,在点击按钮时,我将能够创建一个新的谷歌电子表格。 Can someone help me with the syntax I need to use?有人可以帮助我使用我需要使用的语法吗? Can I do this?我可以这样做吗?
import React, { Component } from 'react';
const API_KEY = '...';
const sheetID = '...';
class App extends Component {
getSheetValues = async () => {
const request = await fetch(
`https://sheets.googleapis.com/v4/spreadsheets/${sheetID}/values/A1?key=${API_KEY}`
);
const data = await request.json();
console.log(data);
return data;
};
render() {
return (
<div className="App">
<button onClick={this.getSheetValues}>Get sheet values</button>
</div>
);
}
}
export default App;
the below code worked - now i want to find a way to refresh the access token automatically without going to https://developers.google.com/oauthplayground下面的代码有效 - 现在我想找到一种方法来自动刷新访问令牌而不去https://developers.google.com/oauthplayground
'''
import React, { Component } from 'react';
class App extends Component {
getSheetValues = async () => {
const request = await fetch(
`https://sheets.googleapis.com/v4/spreadsheets/${sheetID}/values/A1?key=${API_KEY}`
);
const data = await request.json();
console.log(data);
return data;
};
getNewSheet = async () => {
const request = await fetch(
`https://sheets.googleapis.com/v4/spreadsheets`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${ACCESS_TOKEN}`,
},
body: JSON.stringify({
properties: {
title: 'newSpreadSheetTest',
},
}),
}
);
const data = await request.json();
console.log(data);
return data;
};
render() {
return (
<div className="App">
<button onClick={this.getSheetValues}>Get Spreadsheet values</button>
<br />
<hr />
<button onClick={this.getNewSheet}>Create New Spreadsheet</button>
</div>
);
}
}
export default App;
'''
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.