I am trying to invoke Google IoT core APIs using java. When I use JSON file provided on console while creating the service account, to create GoogleCredentials object, it has serviceAccountProjectID field set to appropriate value, however when I use Application Default Credentials(on compute engine vm bound to the same service account) to get the GoogleCredentials, the serviceAccountProjectID is set to null. Is there a way to get the ProjectID pro-grammatically?
Asked
Active
Viewed 230 times
1 Answers
0
You can use the query the metadata server [1] to check the project.
$ curl "http://metadata.google.internal/computroject-id" -H "Metadata-Flavor: Google"
[1] https://cloud.google.com/compute/docs/storing-retrieving-metadata#querying

Pol Arroyo
- 485
- 2
- 7
-
I need a way to do it through java code. I know, we can invoke this command from java code, need a better way. Anyways thanks for replying – Rahul Agrawal Feb 16 '18 at 11:21