title: How to pull pubsub metrics from google api
body: <p>We are using our own logging solution because stackdriver is su...bpar. I want to pull the metrics on how many unacknowledged messages there are in the pubsub. Started to read the docs on that and they are all over the place. </p>
  
  <p>Found this page: 
  <a href="https://cloud.google.com/monitoring/api/metrics" rel="nofollow noreferrer">https://cloud.google.com/monitoring/api/metrics</a>
  Despite being under the api it does not describe any api calls, but does contain the description of the metric I want to extract. </p>
  
  <p>Now I am thinking I need to use the monitoring api to extract what I need somehow: 
  <a href="https://cloud.google.com/monitoring/api/ref_v3/rest/" rel="nofollow noreferrer">https://cloud.google.com/monitoring/api/ref_v3/rest/</a></p>
  
  <p>So I use the api explorer to try a couple of methods: 
  <a href="https://developers.google.com/apis-explorer/#search/monitoring/monitoring/v3/monitoring.projects.groups.list" rel="nofollow noreferrer">https://developers.google.com/apis-explorer/#search/monitoring/monitoring/v3/monitoring.projects.groups.list</a></p>
  
  <p>I query and gives me an available url: </p>
  
  <p><code>GET https://monitoring.googleapis.com/v3/projects/myprojectname/groups?key={YOUR_API_KEY}</code></p>
  
  <p>I go to my project's console (api &amp; credentials page) and generate an api key without restrictions and paste it in trying to curl. </p>
  
  <pre><code>curl https://monitoring.googleapis.com/v3/projects/myproject/groups?key=myrandomkeylkjlkj
  {
    "error": {
      "code": 401,
      "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
      "status": "UNAUTHENTICATED"
    }
  }
  </code></pre>
  
  <p>Why is this happening? How can I get the metrics? I went to the url provided but it explains oauth token creation and has nothing regarding the api keys. I just need to curl things to make sure I am going the right way. </p>