Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将react应用程序与google sheets同步_Javascript_Node.js_Reactjs - Fatal编程技术网

Javascript 将react应用程序与google sheets同步

Javascript 将react应用程序与google sheets同步,javascript,node.js,reactjs,Javascript,Node.js,Reactjs,我有一个react应用程序,它显示来自谷歌表单的数据 事实证明,我无法直接从react客户端从Google工作表中获取数据,因为它是在服务器上运行的(如果我错了,请判断我) 我的问题是:我可以创建一个最小的server.js吗,比如说使用,它仍然是静态的 目标是让它在github页面这样的主机上运行,同时每隔几分钟刷新一次数据 我读过一些帖子和文章(例如),但我仍然没有找到关于如何部署这样一个项目的答案。据我所知,您无法在github pages这样的托管平台上运行服务器,但您可以使用按钮进行刷

我有一个react应用程序,它显示来自谷歌表单的数据

事实证明,我无法直接从react客户端从Google工作表中获取数据,因为它是在服务器上运行的(如果我错了,请判断我)

我的问题是:我可以创建一个最小的server.js吗,比如说使用,它仍然是静态的

目标是让它在github页面这样的主机上运行,同时每隔几分钟刷新一次数据


我读过一些帖子和文章(例如),但我仍然没有找到关于如何部署这样一个项目的答案。

据我所知,您无法在github pages这样的托管平台上运行服务器,但您可以使用按钮进行刷新。为此,我可以阅读这篇博文


这里还有Github上的源代码:

据我所知,您不能在Github pages这样的托管平台上运行服务器,但可以使用按钮进行刷新。为此,我可以阅读这篇博文

这里还有Github上的源代码:

我终于管理好了

在我的
index.html
中,我必须添加
,这使得
window.gapi
在应用程序中随处可见

My
App.js
现在包含一个登录功能,可以加载google客户端库

最后,表示组件的数据如下所示:

export default class PartnerTable extends Component {
  constructor(props) {
    super(props);

    this.state = {
      partners: []
    };

    this.load = this.load.bind(this);
  }

  componentWillMount() {
    this.setState({ loading: true });
    // Load an initial state
    this.load();
  }

  componentDidMount() {
    // sync every one minute
    setInterval(() => {
      this.setState({ loading: true });
      this.load();
    }, ONE_MINUTE);
  }

  callback(values) {
    this.setState({ partners });
  }

  errorCallback(errorMessage) {
    console.error(errorMessage);
  }

  load() {
    window.gapi.client.load('sheets', 'v4', async () => {
      return window.gapi.client.sheets.spreadsheets.values
        .get({
          spreadsheetId: '<YOUR SPREADSHEET ID>',
          range: 'A1:E'
        })
        .then(response => {
          const { values } = response.result;
          this.callback(values);
        })
        .catch(error => {
          this.errorCallback(error);
        });
    });
  }

  render() {
    const { partners } = this.state;
    return <div>{'<some way to represent the data, e.g. as table>'}</div>;
  }
}
导出默认类PartnerTable扩展组件{
建造师(道具){
超级(道具);
此.state={
合作伙伴:[]
};
this.load=this.load.bind(this);
}
组件willmount(){
this.setState({loading:true});
//加载初始状态
这个.load();
}
componentDidMount(){
//每分钟同步一次
设置间隔(()=>{
this.setState({loading:true});
这个.load();
},一分钟);
}
回调(值){
this.setState({partners});
}
errorCallback(errorMessage){
控制台错误(错误消息);
}
加载(){
load('sheets','v4',async()=>{
return window.gapi.client.sheets.spreadsheets.values
.得到({
电子表格ID:“”,
范围:“A1:E”
})
。然后(响应=>{
const{values}=response.result;
这是一个回调(值);
})
.catch(错误=>{
这个.errorCallback(错误);
});
});
}
render(){
const{partners}=this.state;
返回{''};
}
}
我终于成功了

在我的
index.html
中,我必须添加
,这使得
window.gapi
在应用程序中随处可见

My
App.js
现在包含一个登录功能,可以加载google客户端库

最后,表示组件的数据如下所示:

export default class PartnerTable extends Component {
  constructor(props) {
    super(props);

    this.state = {
      partners: []
    };

    this.load = this.load.bind(this);
  }

  componentWillMount() {
    this.setState({ loading: true });
    // Load an initial state
    this.load();
  }

  componentDidMount() {
    // sync every one minute
    setInterval(() => {
      this.setState({ loading: true });
      this.load();
    }, ONE_MINUTE);
  }

  callback(values) {
    this.setState({ partners });
  }

  errorCallback(errorMessage) {
    console.error(errorMessage);
  }

  load() {
    window.gapi.client.load('sheets', 'v4', async () => {
      return window.gapi.client.sheets.spreadsheets.values
        .get({
          spreadsheetId: '<YOUR SPREADSHEET ID>',
          range: 'A1:E'
        })
        .then(response => {
          const { values } = response.result;
          this.callback(values);
        })
        .catch(error => {
          this.errorCallback(error);
        });
    });
  }

  render() {
    const { partners } = this.state;
    return <div>{'<some way to represent the data, e.g. as table>'}</div>;
  }
}
导出默认类PartnerTable扩展组件{
建造师(道具){
超级(道具);
此.state={
合作伙伴:[]
};
this.load=this.load.bind(this);
}
组件willmount(){
this.setState({loading:true});
//加载初始状态
这个.load();
}
componentDidMount(){
//每分钟同步一次
设置间隔(()=>{
this.setState({loading:true});
这个.load();
},一分钟);
}
回调(值){
this.setState({partners});
}
errorCallback(errorMessage){
控制台错误(错误消息);
}
加载(){
load('sheets','v4',async()=>{
return window.gapi.client.sheets.spreadsheets.values
.得到({
电子表格ID:“”,
范围:“A1:E”
})
。然后(响应=>{
const{values}=response.result;
这是一个回调(值);
})
.catch(错误=>{
这个.errorCallback(错误);
});
});
}
render(){
const{partners}=this.state;
返回{''};
}
}