title: Google Cloud Function Accessing BigQuery
body: <p>I'm trying to write a google cloud function that accesses my bigquery data. However, I get an error when I run it. It works correctly if I run under the local emulator, but not when deployed.</p>
  
  <p>My package.json:</p>
  
  <pre><code>{
    "dependencies": {
      "@google-cloud/bigquery": "^0.9.6"
    }
  }
  </code></pre>
  
  <p>index.js</p>
  
  <pre><code>var BigQuery = require('@google-cloud/bigquery');
  
  exports.hello = function hello(req, res) {
  
      var bigQuery = BigQuery({ projectId: 'influence-ranking' });
      bigQuery.query({
          query: 'SELECT label from `influence-ranking.wikidata.labels` LIMIT 1',
          useLegacySql: false
      }).then(function () {
          return res.status(200).send('hello');
      }).catch(function (error) {
          return res.status(500).json(error);
      });
  };
  </code></pre>
  
  <p>I deploy the function:</p>
  
  <pre><code>$ gcloud beta functions deploy hello --stage-bucket influence-ranking-web --trigger-http --project influence-ranking
  
  Copying file:///tmp/tmpwR3Sza/fun.zip [Content-Type=application/zip]...
  / [1 files][  7.3 KiB/  7.3 KiB]                                                
  Operation completed over 1 objects/7.3 KiB.                                      
  Deploying function (may take a while - up to 2 minutes)...done.                                                                      
  availableMemoryMb: 256
  entryPoint: hello
  httpsTrigger:
    url: https://us-central1-influence-ranking.cloudfunctions.net/hello
  labels:
    deployment-tool: cli-gcloud
  latestOperation: operations/aW5mbHVlbmNlLXJhbmtpbmcvdXMtY2VudHJhbDEvaGVsbG8vdHJoV1pjeWlnSkk
  name: projects/influence-ranking/locations/us-central1/functions/hello
  serviceAccount: tfc7c97f9c5ac6052-tp@appspot.gserviceaccount.com
  sourceArchiveUrl: gs://influence-ranking-web/us-central1-hello-poucdhlbhptc.zip
  status: READY
  timeout: 60s
  updateTime: '2017-09-20T18:42:22Z'
  versionId: '15'
  
  
  $ curl https://us-central1-influence-ranking.cloudfunctions.net/hello
  {"code":403,"errors":[{"domain":"usageLimits","reason":"accessNotConfigured","message":"Access Not Configured. BigQuery API has not been used in project 283683622993 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/bigquery.googleapis.com/overview?project=283683622993 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.","extendedHelp":"https://console.developers.google.com/apis/api/bigquery.googleapis.com/overview?project=283683622993"}],"message":"Access Not Configured. BigQuery API has not been used in project 283683622993 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/bigquery.googleapis.com/overview?project=283683622993 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."}
  </code></pre>
  
  <p>The link in the error message gives the error:</p>
  
  <pre><code>The API "bigquery.googleapis.com" doesn't exist or you don't have permission to access it
  </code></pre>
  
  <p>It looks like the project parameter doesn't correspond to the project number listed for my project in google cloud console. So it makes me think that somehow I'm getting the request being made against the wrong project, but I can't figure out how.</p>