Created
March 21, 2022 18:03
-
-
Save GaetanoPiazzolla/70977da36227fc03ce0e783a4d53efb9 to your computer and use it in GitHub Desktop.
Create an Access token from the Service Account key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.api.services.forms.v1.FormsScopes; | |
import com.google.auth.oauth2.GoogleCredentials; | |
import java.io.IOException; | |
import java.util.Objects; | |
public static String getAccessToken() throws IOException { | |
GoogleCredentials credential = GoogleCredentials.fromStream(Objects.requireNonNull( | |
Main.class.getResourceAsStream("cred.json"))).createScoped(FormsScopes.all()); | |
return credential.getAccessToken() != null ? | |
credential.getAccessToken().getTokenValue() : | |
credential.refreshAccessToken().getTokenValue(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment