1

I am writing an application to fetch query logs from google cloud sql using stack driver monitoring. I am able to retrieve the logs using API explorer. I will be using a curl call to download the logs.

curl --header "Authorization: Bearer ACCESS_TOKEN" --header 'Content-Type: application/json' --header 'x-referer: https://developers.google.com' -X POST --data '{"resourceNames":["projectname"],"filter":"logName=logname"}' "https://content-logging.googleapis.com/v2/entries:list?fields=entries(jsonPayload%2ClogName%2Coperation%2CreceiveTimestamp%2CtextPayload%2Ctimestamp)&key=APIkey"

API key is available in the interface. I have downloaded the json with client details. But I am not able to find any documentation on how to generate ACCESS_TOKEN in this case. Can someone please help me on this?

Sandy
  • 1,043
  • 2
  • 21
  • 32

1 Answers1

0

You can try:

curl -H "Authorization: Bearer "$(gcloud auth application-default  
print-access-token) ... 

or set:

ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"

and then:

curl --header "Authorization: Bearer ${ACCESS_TOKEN}" ...
cryotek
  • 508
  • 2
  • 9
  • should I install gcloud(Cloud SDK) in my machine to run this command? – Sandy Apr 24 '18 at 15:57
  • Is there any other way to get ACCESS_TOKEN? I do not want to install any other tool on my machine. – Sandy Apr 25 '18 at 13:10
  • It is possible to generate ACCESS_TOKEN using JWT. I am trying with that now. – Sandy Apr 25 '18 at 13:11
  • You can use service account authorization without OAuth: developers.google.com/identity/protocols/…, but have to call logging.googleapis.com (instead of content-logging.googleapis.com). It is a supported API: github.com/googleapis/googleapis/tree/master/google – cryotek May 01 '18 at 10:55