We are planning to host a topic (pub/sub) on google cloud and have created a topic and client service account.
Now I have to connect to the topic and publish the messages. I was trying to authenticate before publishing the messages. But couldn't find a suitable approach for my scenario "Local Server to Google Cloud authentication using rest API".
Please help me if there is any approach available for this method.
Here is the code I am using but is giving browser redirect response instead of access token. Please find the code below and response
private static Credential authorize() throws Exception { HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); GoogleClientSecrets clientSecrets = JSON_FACTORY.fromReader(new InputStreamReader(new FileInputStream(new File(KEY_FILE_LOCATION))), GoogleClientSecrets.class); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.out.println("Enter Client ID and Secret in client_secrets.json"); System.exit(1); } GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( httpTransport, JSON_FACTORY, clientSecrets, Collections.singleton(PubsubScopes.PUBSUB)).build(); return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize(SERVICE_ACCOUNT_EMAIL); } Please open the following address in your browser: