I have one Spreadsheet file in my Google Drive which i want to sync from an Android Application. After a successful sync I have some search criteria in my apps, I want results based on this criteria from the file which I sync. I am doing this for the first time and not getting good resources to start with.
1) How to sync Google Drive file in Android App?
2) How to retrieve particular data from the Spreadsheet which i have synced?
Note – I am also confused between Google Docs API & Google Drive SDK.
What to use in my app?
I have only one file to sync every time, not all the files. And the file is open to all with a private key.
I have implemented some code but it’s not working. Below is my spreadsheet public url which i want to sync in my android app.
I am following steps from here.
try {
String USERNAME = "xxxxx";
String PASSWORD = "xxxxx";
SpreadsheetService service =
new SpreadsheetService("Testing");
service.setUserCredentials(USERNAME, PASSWORD);
// TODO: Authorize the service object for a specific user (see other sections)
// Define the URL to request. This should never change.
URL SPREADSHEET_FEED_URL = new URL(
"https://spreadsheets.google.com/feeds/spreadsheets/private/full");
// Make a request to the API and get all spreadsheets.
SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL,
SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
if (spreadsheets.size() == 0) {
// TODO: There were no spreadsheets, act accordingly.
}
// TODO: Choose a spreadsheet more intelligently based on your
// app's needs.
SpreadsheetEntry spreadsheet = spreadsheets.get(0);
System.out.println(spreadsheet.getTitle().getPlainText());
// Make a request to the API to fetch information about all
// worksheets in the spreadsheet.
List<WorksheetEntry> worksheets = spreadsheet.getWorksheets();
// Iterate through each worksheet in the spreadsheet.
for (WorksheetEntry worksheet : worksheets) {
// Get the worksheet's title, row count, and column count.
String title = worksheet.getTitle().getPlainText();
int rowCount = worksheet.getRowCount();
int colCount = worksheet.getColCount();
// Print the fetched information to the screen for this worksheet.
System.out.println("\t" + title + "- rows:" + rowCount + " cols: " + colCount);
}
} catch (Exception e) {
e.printStackTrace();
}
I got it. I have not added the permission and that is why it is giving me error. We need to add below permission for authorization.