This is a draft, the content is not complete and of poor quality!
Thi
Google’s documentation is like an ocean. It’s not easy to find a right one to start. This note contains only basic things that I’ve already worked with. Trying your own hand at Google’s APIs will help you understand more.
Understand
roles -- If you decide to create a service account, you will need to assign a role to some
users/emails. Each role has different rights to use your data.
If you come from Dialogflow Console > choose
an agent > click on the gear next to the its name > Click on "Project ID" to open Google Cloud
Platform Console.
If you come from GCP Console, it's the same.
Follow these
steps to generate a JSON key (you'll download a JSON file). Store your JSON file in
df-samples/credential.json. Note down the project_id, we will use
it later, eg. project_abc.
Run each time you wanna test export
GOOGLE_APPLICATION_CREDENTIALS="/home/thi/df-samples/credential.json" OR save this line to
/home/thi/.bashrc or /home/thi/.zshrc (if you use ZSH) and then refresh the current terminal (with this method,
you don't need to run again previous line).
Alternative: You don't have to use system variable
GOOGLE_APPLICATION_CREDENTIALS if you don't want. In credential.json, copy
private_key and client_email and then use them as,
Make the same things in "Step by step". At step 7, create search-agents.js with the same content
as samples/set-agent.js.
We are going to change this file.
Then run `node search-agents.js`.
Different locations?
The example in "Try something outside..." gives us an example of using different regions. Below are some remarks:
On DF console, you can create some agents in a different
regions, default is global (or us).
On the Google's documentations, they don't mention about the usage of location. If they say parent =
"projects/-", we shoud use parent = "projects/-" + "/locations/" + location
where location can be one of "Region ID".
<!-- OLD --><script src="https://apis.google.com/js/platform.js"asyncdefer></script><!-- NEW --><script src="https://accounts.google.com/gsi/client"asyncdefer></script>
What’s this gapi? You can use it completely inside an HTML file without using any backend.
💡 Tip: If you are using VSCode, you can install the Live Server extension to quickly create a server (port 5500 by default). Just click the button at the bottom right of the file and a website will appear.
Using something like Live Server and
open authSample.html.
Make a test.
Make sure you create the "OAuth consent screen" before you create "OAuth 2.0 Client IDs". The
"consent screen" is the popup window that contains all the information about the scopes your app
will ask users for permission.
Make sure you add http://localhost:5500 (which is created in step 4) to "Authorized
JavaScript origins" and "Authorized redirect URIs". You may have to wait a few "ten minutes" for
everything to work. Without this step, you may encounter the error mismatch_uri.
Make sure you create the “OAuth consent screen” before you create “OAuth 2.0 Client IDs”. The “consent screen” is the popup window that contains all the information about the scopes your app will ask users for permission.
Make sure you add http://localhost:5500 (which is created in step 4) to “Authorized JavaScript origins” and “Authorized redirect URIs”. You may have to wait a few “ten minutes” for everything to work. Without this step, you may encounter the error mismatch_uri.
Examples
projects.agent.search
GET https://{endpoint}/v2/{parent=projects/*}/agent:search