Looking at the Translate API there are a few services available:
- language detection
- lists of languages supported for translation
- translation
Under language detection:
-
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
Under language translations
- there are additional fields including a 'fields' field:
- allows one to customise output instead of receiving the entire response
Creating a bucket via the API:
- Make sure that the API is enabled under the current project under APIs and Services
- Visiting Cloud Storage should show no buckets for a new project
- In API explorer select the service for inserting / creating a new bucket
- 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
- 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
- We can see which scope are enabled for this API in the top-right question mark next to the OAuth toggler
- Once the bucket is created
- we can see the request and response
- we can see the bucket in the project
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.
Find Cloud Storage JSON API v1 and click to view the scopes available on that API.
To read from the bucket created:
- select teh readonly scope
- authorise
- 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
- 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
https://www.googleapis.com/storage/v1/b/{bucket}/o
-
make the request and view the response
-