I'm working with SpreadsheetService and I'm trying to get the feed from the spreadsheets URL (https://spreadsheets.google.com/feeds/spreadsheets/private/full).
I'm doing the authentication using a service key. Seems like the authentication is working, but when I'm trying to get the feed I'm getting an error:
ServiceException (com.google.gdata.util.ServiceException: Internal Server Error).
This is the authentication method:
public static Credential authenticateWithServiceKey(GoogleApiProperties properties) throws IOException {
GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream("src/main/resources/prime-moment-274810-940d01c0244d.json"))
.createScoped(Collections.singleton(properties.getScope()));
return credential;
}
This is how I create the service and authenticate using the Credential object from the method above:
public void init(GoogleApiProperties properties) throws IOException, GeneralSecurityException {
Credential credential = GoogleAuthentication.authenticateWithServiceKey(properties);
service = new SpreadsheetService(properties.getApplicationName());
service.setOAuth2Credentials(credential);
}
And this is where I'm trying to get the list of spreadsheets:
public List<String> getContentList() throws IOException, ServiceException {
// Define the URL to request. This should never change.
URL SPREADSHEET_FEED_URL = new URL(SPREADSHEETS_URL);
// Make a request to the API and get all spreadsheets.
SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
// Return a list of spreadsheet names
return feed.getEntries().stream()
.map(entry -> entry.getTitle().getPlainText())
.collect(Collectors.toList());
}
The exception is coming right after the service.getFeed
call.
When I'm using the regular method for obtaining OAuth2.0 Credential, it works fine, but it require manual intervention (accepting the connection via Google page).