I tried to user the google sheet API v4 to create a new sheet. I create it successfully. However, I found that the sheet is setting as I am the only one is able to access. My goal is to allow users have the url link can access the sheet in Java request.
I tried to set google credidential to null when create spreadsheet, but it use as to create the spreadsheet in drive. Thus, this is not work. I browser it library class and api, but I cannot found anything related to the permission.
I am not so sure the way I create the spreadsheet is on right way. Here is my code:
public class CreateSpreadSheetTask extends AsyncTask<Void, Void, Void> { private com.google.api.services.sheets.v4.Sheets mService = null; private Exception mLastError = null; private String title = null; private CreateSpreadsheetListener listener = null; public CreateSpreadSheetTask(GoogleAccountCredential credential, String title, CreateSpreadsheetListener listener) { HttpTransport transport = AndroidHttp.newCompatibleTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); mService = new Sheets.Builder( transport, jsonFactory, credential) .setApplicationName("Google Sheets API Android Quickstart") .build(); this.title = title; this.listener = listener; } @Override protected Void doInBackground(Void... params) { try { this.listener.onRecvCreateSpreadsheet(getSpreadsheetFromApi()); } catch (Exception e) { e.printStackTrace(); mLastError = e; cancel(true); } return null; } private Spreadsheet getSpreadsheetFromApi() throws IOException { Spreadsheet spreadsheet = new Spreadsheet(); SpreadsheetProperties properties = new SpreadsheetProperties(); properties.setTitle(this.title); spreadsheet.setProperties(properties); Sheets.Spreadsheets.Create request = mService.spreadsheets().create(spreadsheet); return request.execute(); } }
spreadsheetIdthat the Sheets API gives you in the response fromCreate.