3

I am using following code for reading data from spreadsheet but it is not working.

    import java.net.URL;
    import com.google.gdata.client.spreadsheet.SpreadsheetService;
    import com.google.gdata.data.spreadsheet.ListEntry;
    import com.google.gdata.data.spreadsheet.ListFeed;
    import com.google.gdata.data.spreadsheet.SpreadsheetEntry;
    import com.google.gdata.data.spreadsheet.WorksheetEntry;
    import com.google.gdata.util.ServiceException;

    public class ReadSpreadsheet {
    public static final String GOOGLE_ACCOUNT_USERNAME = "[email protected]";
    // Fill in google account username
    public static final String GOOGLE_ACCOUNT_PASSWORD = "xxxx"; // Fill in google account password
  public static final String SPREADSHEET_URL = "https://spreadsheets.google.com/feeds/spreadsheets/1L8xtAJfOObsXL-XemliUV10wkDHQNxjn6jKS4XwzYZ8"; //Fill in google spreadsheet URI

  public static void main(String[] args) throws IOException, ServiceException
  {
    /** Our view of Google Spreadsheets as an authenticated Google user. */
    SpreadsheetService service = new SpreadsheetService("Print Google Spreadsheet Demo");

    // Login and prompt the user to pick a sheet to use.
    service.setUserCredentials(GOOGLE_ACCOUNT_USERNAME, GOOGLE_ACCOUNT_PASSWORD);

    // Load sheet
    URL metafeedUrl = new URL(SPREADSHEET_URL);
    SpreadsheetEntry spreadsheet = service.getEntry(metafeedUrl, SpreadsheetEntry.class);
    URL listFeedUrl = ((WorksheetEntry) spreadsheet.getWorksheets().get(0)).getListFeedUrl();

    // Print entries
    ListFeed feed = (ListFeed) service.getFeed(listFeedUrl, ListFeed.class);
    for(ListEntry entry : feed.getEntries())
    {
      System.out.println("new row");
      for(String tag : entry.getCustomElements().getTags())
      {
        System.out.println("     "+tag + ": " + entry.getCustomElements().getValue(tag));
      }
    }
  }
    }

I am getting issue is following line: SpreadsheetService service = new SpreadsheetService("Print Google Spreadsheet Demo");

here I need to write application name in some specific format that I have followed using following link: https://developers.google.com/gdata/javadoc/com/google/gdata/client/spreadsheet/SpreadsheetService.

but I cannot understand the version format which should be written like "[company-id]-[app-name]-[app-version]"

moreover I am using this code in my selenium script for reading/writing data. so please anyone suggest me the actual solution, also if it is possible to reading/writing data from selenium without using this code than it will be great.

error that I am getting is

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399)
at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableXmlTypes(AltFormat.java:387)
at com.google.gdata.wireformats.AltFormat.<clinit>(AltFormat.java:49)
at com.google.gdata.client.Service.<clinit>(Service.java:558)
at ReadSpreadsheet.main(ReadSpreadsheet.java:21)

and I am using following jars in this project:

    gdata-core-1.0.jar
    gdata-spreadsheet-3.0.jar
    guava-20.0
    mailapi.jar`
2
  • Please see here stackoverflow.com/a/25457199 Commented Jan 11, 2017 at 1:59
  • Is it necessary to use oauth process for fetching data from spreadsheet??, In my current code I am already using my credential so it should not require any more authentication process. please suggest. Commented Jan 11, 2017 at 7:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.