Home > Software design >  Get any information from Google Big Query
Get any information from Google Big Query

Time:04-14

I need a bit help with BigQuery API, because I can't get or post any HTTP request with Auth problem.

I have found information about how to send http requests to GBQ on this links:

https://developers.google.com/explorer-help/ https://cloud.google.com/bigquery/docs/reference/rest/?apix=true

More than that, I had an opportunity to get info about my dataset using built-in API. But can't find info about API_KEY and ACCESS_TOKEN.

I need an example of request or maybe links, where can i find/create my tokens. Client ID and Client secret are also created by me.

Here is cURL which works on Try This Method (https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets/get):

curl \
  'https://bigquery.googleapis.com/bigquery/v2/projects/PROJECT/datasets/DATASET?key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed

enter image description here

CodePudding user response:

You may try using curl method instead in Linux/MacOS(I used Cloud shell) or Windows so that you can explicitly define your service key in the environment. For service account and keys creation, and also setting it into your environment you can refer to this documentation.

Command:

curl -X GET \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
"https://bigquery.googleapis.com/bigquery/v2/projects/{my-projectId}/datasets/{my-datasetId}"

Output:

a@cloudshell:~ (a)$ curl -X GET \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
"https://bigquery.googleapis.com/bigquery/v2/projects/{my-projectId}/datasets/{my-datasetId}"
{
  "kind": "bigquery#dataset",
  "etag": "Sg/LBN/riP3JmF QDeKpLg==",
  "id": "{my-projectId}:{my-datasetId}",
  "selfLink": "https://bigquery.googleapis.com/bigquery/v2/projects/{my-projectId}/datasets/{my-datasetId}",
  "datasetReference": {
    "datasetId": "{my-datasetId}",
    "projectId": "{my-projectId}"
  },
  "access": [
    {
      "role": "WRITER",
      "specialGroup": "projectWriters"
    },
    {
      "role": "OWNER",
      "specialGroup": "projectOwners"
    },
    {
      "role": "OWNER",
      "userByEmail": "{my-email}"
    },
    {
      "role": "READER",
      "specialGroup": "projectReaders"
    }
  ],
  "creationTime": "1640656847727",
  "lastModifiedTime": "1640656847727",
  "location": "{my-location}",
  "type": "DEFAULT"
}
  • Related