Google Sheets API with React Native

2019-09-20 23:36发布

问题:

New to react-native. Trying to do simple crud operations on a google spreadsheet located in google drive. I've successfully implemented the packages for react-native-google-signin and react-native-google-drive-api-wrapper and can see my spreadsheets. Next step is finding a react-native package that implements google sheets API v4. I've tried Iwark's/react-native-spreadsheet for react/node.js but it produces errors when trying to build in a react-native environment. Any direction would be appreciated.

回答1:

I am hoping can do this using googleapis and google-auth-library two libraries; Then initialise the apis by doing

var authClient = new googleAuth();
  var auth = new authClient.OAuth2();
  auth.credentials = {
    access_token: accessToken
  };
  this.service = google.sheets({version: 'v4', auth: auth});

Then use the this.service

If this doesn't make much sense, wait for few hours or tomorrow, I will help you with a working copy. :)

EDIT: This is what I think you should do,"

  1. If you have your spreadsheet public, follow this
  2. If your spreadsheet is private

a) You need to make the user login (use firebase google login), then get the access_token and do a get with access_token in https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId} or post request etc.

b) Make a post request in your node server where you handle all of these

Note: I might help you with a working example this weekend.