Failed to authenticate using Google via Java SDK to read spreadsheet data

When I try to authenticate with Google, it throws an exception during authentication (check the service name).

I used the Google Java SDK for authentication.

SpreadsheetService service = new SpreadsheetService("Print Google Spreadsheet Demo");   //this is my application name that i created in developer console
            service.setUserCredentials(MY_GOOGLE_EMAIL_ADDRESS, 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);

An exception was thrown by the method setUserCredentials().

An exception:

com.google.gdata.util.AuthenticationException: Error authenticating (check service name)
    at com.google.gdata.client.GoogleAuthTokenFactory.getAuthException(GoogleAuthTokenFactory.java:628)
    at com.google.gdata.client.GoogleAuthTokenFactory.getAuthToken(GoogleAuthTokenFactory.java:500)
    at com.google.gdata.client.GoogleAuthTokenFactory.setUserCredentials(GoogleAuthTokenFactory.java:346)
    at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:362)
    at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:317)
    at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:301)

Is there any configuration that I skipped before accessing a Google spreadsheet?

+5
source share

All Articles