Google Cloud Fundamentals
API Explorer and OAuth 2.0 Playground

API Explorer and OAuth 2.0 Playground

API Explorer

API Explorer (opens in a new tab)


Translate API

Looking at the Translate API (opens in a new tab) there are a few services available:

  • language detection
  • lists of languages supported for translation
  • translation

Language Detection

Under language detection (opens in a new tab):

  • we are provided with fields to make requests

    • anything in red is required
  • requests can be done via OAuth 2.0 or as unauthorised requests

  • requests are sent via URL parameters:

    GET https://translation.googleapis.com/language/translate/v2/detect?q=bonjour&key={YOUR_API_KEY}
  • response data is JSON

Language Translation

Under language translations (opens in a new tab)

  • there are additional fields including a 'fields' field:
    • allows one to customise output instead of receiving the entire response

Cloud Storage

Cloud Storage APIs (opens in a new tab)

Creating a bucket via the API:

  1. Make sure that the API is enabled under the current project under APIs and Services (opens in a new tab)
  2. In API explorer select the service for inserting / creating a new bucket (opens in a new tab)
  3. Add fields
    • under 'Request body' there's a field with name but no value - these are required fields
    • add another field under 'Request body' for storageClass, and select from option suggested by the question mark
  4. Creating a bucket has to be done with authorisation, as it will affect our project directly
    • a modal appears requesting which scopes are authorised for the bucket
  5. We can see which scope are enabled for this API in the top-right question mark next to the OAuth toggler
  6. Once the bucket is created

To add to the bucket we can use gsutil:

$ gsutil cp *.png gs://[your-bucket-id]
Copying file://[my-files]...
| [1 files][ 28.4 MiB/ 28.4 MiB]    3.1 MiB/s
Operation completed over 1 objects/28.4 MiB.

OAuth 2.0 Playground

OAuth Playground (opens in a new tab)

Find Cloud Storage JSON API v1 and click to view the scopes available on that API.

To read from the bucket created:

  1. select teh readonly scope
  2. authorise
  3. exchange authorisation code for tokens
    • once exchanged, we receive an access token and refresh token in the response
    • our app uses the access token to make requests to the API
    • access tokens have a lifespan - this is where the refresh token comes into play
    • the refresh token is used to refresh the lifespan of the access token
    • refreshing the token changes the access token and resets the lifespan
  4. make a request:
    • we can create the request by hand,

    • or we can list all possible operations using the button provided

    • select 'list objects' and replace the bucket name placeholder in the input

    • make the request and view the response