2
votes

Here is the error dat i'm getting while trying to make an authentication call to bigquery

HttpError: <HttpError 400 when requesting https://www.googleapis.com/bigquery/v2/projects/ClientId/datasets/samples/tables/natality?alt=json returned "Invalid project ID 'ClientId'. Project IDs must contain 6-63 lowercase letters, digits, or dashes. IDs must start with a letter and may not end with a dash.">

Here is my main.py

import httplib2
import os
from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from oauth2client.appengine import oauth2decorator_from_clientsecrets
from bqclient import BigQueryClient


PROJECT_ID = "########"  this is the Client Id 
DATASET = "samples"
TABLE = "natality"


CLIENT_SECRETS = os.path.join(os.path.dirname(__file__),
    'client_secrets.json')

http = httplib2.Http(memcache)
decorator = oauth2decorator_from_clientsecrets(CLIENT_SECRETS,
    'https://www.googleapis.com/auth/bigquery')

bq = BigQueryClient(http, decorator)

class MainHandler(webapp.RequestHandler):
    @decorator.oauth_required
    def get(self):
        self.response.out.write("Hello Dashboard!\n")
        modTime = bq.getLastModTime(PROJECT_ID, DATASET, TABLE)
        if modTime is not None:
            msg = 'Last mod time = ' + modTime
        else:
            msg = "Could not find last modification time.\n"
        self.response.out.write(msg)

application = webapp.WSGIApplication([
   ('/', MainHandler),
   (decorator.callback_path, decorator.callback_handler())
], debug=True)

def main():
   run_wsgi_app(application)

if __name__ == '__main__':
    main()

And here is the app.yaml

application: hellomydashboard
version: 1
runtime: python
api_version: 1

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: .*
  script: main.py

And here is the bqclient.py

import httplib2
from apiclient.discovery import build
from oauth2client.appengine import oauth2decorator_from_clientsecrets

class BigQueryClient(object):
    def __init__(self, http, decorator):
        """Creates the BigQuery client connection"""
        self.service = build('bigquery', 'v2', http=http)
        self.decorator = decorator

    def getTableData(self, project, dataset, table):
        decorated = self.decorator.http()
        return self.service.tables().get(projectId=project, datasetId=dataset,
            tableId=table).execute(decorated)

    def getLastModTime(self, project, dataset, table):
        data = self.getTableData(project, dataset, table)
        if data is not None and 'lastModifiedTime' in data:
            return data['lastModifiedTime']
        else:
            return None

    def Query(self, query, project, timeout_ms=10000):
        query_config = {
            'query': query,
            'timeoutMs': timeout_ms
        }
        decorated = self.decorator.http()
        result_json = (self.service.jobs()
                       .query(projectId=project, body=query_config)
                       .execute(decorated))

        return result_json

I also tried replacing the ClientId with Project Id as said in the error but it gives another error

HttpError: <HttpError 404 when requesting https://www.googleapis.com/bigquery/v2/projects/hellodashboard87/datasets/samples/tables/natality?alt=json returned "Not Found: Dataset hellodashboard87:samples">

I'm following the tutorial on this page https://developers.google.com/bigquery/articles/dashboard#firstcall

2
The error message you've posted says it all: "Invalid project ID 'ClientId'. Project IDs must contain 6-63 lowercase letters, digits, or dashes.". Why don't you try changing PROJECT_ID to something like project-id, i.e., with only lowercase letters, digits or dashes. - Pedro Romano
Ya i did try it with the project Id also but it giving another error HttpError: <HttpError 404 when requesting googleapis.com/bigquery/v2/projects/hellodashboard87/datasets/… returned "Not Found: Dataset hellodashboard87:samples"> - iJade
You can try and use developers.google.com/apis-explorer/#p/bigquery/v2/… to test to see if your inputs are accurate. You can more easily mess around with the API via this method to test your input values quickly. - someone1
well i tried as u said but it shows------ error 404 Not Found - Show headers - { "error": { "errors": [ { "domain": "global", "reason": "notFound", "message": "Not Found: Dataset 440265227336:samples" } ], "code": 404, "message": "Not Found: Dataset 440265227336:samples" } } - iJade
@someone1 it also showing Request GET googleapis.com/bigquery/v2/projects/440265227336/datasets/…{YOUR_API_KEY} Authorization: Bearer ya29.AHES6ZQDddqS_qBwjpn3ngTaaYf33oUScSW2vWtTCYR4z9sGErxX X-JavaScript-User-Agent: Google APIs Explorer do i need an API key for this.If so how to do this.No field to input api key - iJade

2 Answers

2
votes

In order to use the public data sets offered by Google's BigQuery, use the following parameters:

Project ID: publicdata

Dataset ID: samples

Table ID: natality (or whatever you want to use)

In order to use any data sets that you own, switch your Project ID to the one found in the API Console dashboard.

0
votes

In order to use BigQuery, you must create a project in the APIs Console that has BigQuery enabled (I'm assuming you have done this). Once you've created the project, you'll be able to get the project number from the URL, e.g.

https://code.google.com/apis/console/#project:12345XXXXXXX

In the example, the project number is 12345XXXXXXX and this is the value you would use for PROJECT_ID.