我正在编写一个简单的应用程序,我想在用户想要的时候创建一个谷歌电子表格。 我只能到达下面的部分,在那里我可以从现有的谷歌电子表格中读取数据,但我无法对其进行转换,这样,在单击按钮时,我将能够创建一个新的谷歌电子表格。 有人可以帮助我了解我需要使用的语法吗? 我可以这样做吗?
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;
最佳答案
下面的代码有效 - 现在我想找到一种方法来自动刷新访问 token ,而无需转到 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;
'''
关于react-native - 如何通过 react native 应用程序创建新的谷歌电子表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61526278/