[MUSIC PLAYING]
SPEAKER: With Cloud Shell Editor,
you can easily run code from your web browser
and deploy it to the cloud.
In previous videos, we learned how
to deploy Hello, World applications to Cloud Run
and Google Kubernetes Engine.
But what if you want to extend your application
to use other Google Cloud APIs?
Cloud Shell Editor's Cloud Code integration makes it easy.
Cloud Code is a set of IDE plugins
that help you stay productive when developing
cloud-native applications.
In particular, Cloud Code has a Cloud API section
that helps you easily browse available Google Cloud APIs,
enable them, and add API client libraries to your project.
From the Cloud Vision API to the Cloud Storage
API to the BigQuery API, the possibilities are endless.
Let's take a look at how to integrate the Google Cloud
Translate API into a Python Flask web app.
First, visit ide.cloud.google.com
to launch Cloud Shell Editor.
Select Terminal, New Terminal to open a new Cloud Shell terminal
window.
From here, run git clone to clone the sample code
from GitHub.
Then we'll open the sample application
as a new workspace with the cloudshell workspace command.
You can see the list of files in the Explorer panel located
on the left side of the screen.
In the Cloud Shell terminal window,
change directories to the location of the sample app.
To run the sample app locally, run the following terminal
commands.
Press Command and click on the URL displayed to open your app.
Congratulations.
If you see this page, that means you've successfully
run the Hello, World app locally using Cloud Shell Editor.
Back in the Cloud Shell terminal window,
press Control-C to stop the local server.
Now let's set up credentials so that we
can authenticate Google Cloud API
requests for local developments.
In the Cloud Shell terminal window,
run gcloud config set project to set the Google Cloud
project you want to use, then run gcloud auth
application-default login.
When prompted in the terminal if you want to continue,
type in Y and press Enter.
Press Command and click the link displayed in the terminal.
This opens a new browser tab.
Go ahead and authorize access to your account.
Copy the authentication code displayed and paste it
into your terminal.
Now let's go ahead and integrate a new Cloud API
into our application.
First, click on the API icon on the left side of your screen.
This opens the API Explorer, where
you can browse the dozens of Google Cloud APIs for you
to use.
Select the Cloud Translation API,
which allows you to translate between more
than 100 languages.
Under Enable API, click Enable API.
Under Install Client Library, select Python.
Lets copy the name of the translation library
and paste it into our requirements.txt file,
which lists out Python libraries we need for our app.
Now we can configure our Python environment using virtual env
and install dependencies using pip.
Now that the client library's installed,
let's translate some text.
Open the web.py file to edit the Python code.
First, add a line at the top to import the Translation client
library.
Next, we're going to replace our existing root directory
code with the following.
This translates the Hello, World text into Spanish.
Finally, we'll run the updated application with flask run.
Congratulations.
If you see this page with the Spanish text,
you successfully integrated the Cloud Translation API
into your code.
With just a couple of clicks, we were
able to easily integrate a new Google Cloud
API into our project.
Want to try this out yourself?
Check out the interactive tutorial
linked in the description below, or by launching it
from the Cloud Shell Editor welcome page.
Thanks for joining us for our Exploring Cloud Shell Editor
video series.
Make sure to subscribe to the channel for more great videos.
[MUSIC PLAYING]