Fix null precondition while importing a Google Sheet (#3801)

`Credential.Builder()` requires a non-null `AccessMethod`[0], and we were sending
it `null` when actually importing the spreadsheet.

This commit defaults to the same `BearerToken.authorizationHeaderAccessMethod()` that the
`getDriveService()` function was already using.

[0]: https://github.com/googleapis/google-oauth-java-client/blob/v1.31.0/google-oauth-client/src/main/java/com/google/api/client/auth/oauth2/Credential.java#L636-L638

Co-authored-by: Antonin Delpeuch <antonin@delpeuch.eu>
This commit is contained in:
Matías García Isaía 2021-06-28 04:35:05 -03:00 committed by GitHub
parent 26eaacefc6
commit 282cfa6e93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -163,7 +163,7 @@ abstract public class GoogleAPIExtension {
public static Sheets getSheetsService(String token) throws IOException { public static Sheets getSheetsService(String token) throws IOException {
final Credential credential; final Credential credential;
if (token != null) { if (token != null) {
credential = new Credential.Builder(null).build().setAccessToken(token); credential = new Credential.Builder(BearerToken.authorizationHeaderAccessMethod()).build().setAccessToken(token);
} else { } else {
credential = null; credential = null;
} }