You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: retail/interactive-tutorials/README.md
+91-49
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
#Retail Search Interactive Tutorials
1
+
#Retail Search Interactive Tutorials
2
2
3
-
##Run tutorials in Cloud Shell
3
+
##Run tutorials in Cloud Shell
4
4
5
5
To advance with the interactive tutorials, use Retail Search step-by-step manuals on the right side of the Cloud Shell IDE:
6
6

@@ -36,55 +36,61 @@ The Retail API provides you with the following possibilities to:
36
36
37
37
You can find the information about the Retail services in the [documentation](https://cloud.google.com/retail/docs)
38
38
39
-
<!--TODO(tkarasova) update the link to the tutorials when will be published-->
40
39
If you would like to have a closer look at the Retail API features and try them yourself,
41
-
the best option is to use the [Interactive Tutorials](https://cloud.google.com/retail/docs/overview). The tutorials will be launched in the CloudShell environment, and you will be able to request the Retail services and check the response with minimum time and effort.
40
+
the best option is to use the [Interactive Tutorials](https://cloud.google.com/retail/docs/overview). In the documentation chapters find the "Guide me" button, the tutorials will be launched in the CloudShell environment, and you will be able to request the Retail services and check the response with minimum time and effort.
42
41
43
-
The code samples in the directory **python-retail/samples/interactive-tutorials** are explicitly created for use with the Retail Interactive Tutorials.
42
+
The code samples in the directory **java-retail/samples/interactive-tutorials** are explicitly created for use with the Retail Interactive Tutorials.
44
43
45
44
If, for some reason, you have decided to proceed with these code samples without the tutorial, please go through the following steps and set up the required preconditions.
46
45
47
-
### Select your project and enable the Retail API
46
+
##Prepare your work environment
48
47
49
-
Google Cloud organizes resources into projects. This lets you
50
-
collect all the related resources for a single application in one place.
48
+
To prepare the work environment you should perform the following steps:
49
+
- Create a service account.
50
+
- Create a service account key and set it to authorize your calls to the Retail API.
51
+
- Install Google Cloud Retail library.
51
52
52
-
If you don't have a Google Cloud project yet or you're not the owner of an existing one, you can
53
-
[create a new project](https://console.cloud.google.com/projectcreate).
53
+
### There are two ways to set up your work environment:
54
+
55
+
- If you want to **speed up the process** of setting up the working environment, run the script java-retail/samples/interactive-tutorials/samples/interactive-tutorials/src/main/java/user_environment_setup.sh and skip the next **set up the work environment step-by-step** tutorial step:
54
56
55
-
After the project is created, set your PROJECT_ID to a ```project``` variable.
1. To check that the Retail API is enabled for your Project, go to the [Admin Console](https://console.cloud.google.com/ai/retail/).
61
+
- If you want to perform the environment set up step by step along with getting the explanation you should proceed with the next tutorial step.
62
+
63
+
## Set up the work environment step-by-step
62
64
63
65
### Create service account
64
66
65
-
To access the Retail API, you must create a service account.
67
+
To access the Retail API, you must create a service account. Check that you are an owner of your Google Cloud project on the [IAM page](https://console.cloud.google.com/iam-admin/iam).
66
68
67
-
1. To create a service account, follow this [instruction](https://cloud.google.com/retail/docs/setting-up#service-account)
69
+
1. To create a service account, perform the following command:
68
70
69
-
1. Find your service account on the [IAM page](https://console.cloud.google.com/iam-admin/iam),
70
-
click `Edit` icon, add the 'Storage Admin' and 'BigQuery Admin' roles. It may take some timefor changes to apply.
71
+
```bash
72
+
gcloud iam service-accounts create <YOUR_SERVICE_ACCOUNT_ID>
73
+
```
71
74
72
-
1. Copy the service account email in the Principal field.
75
+
1. Assign the needed roles to your service account:
73
76
74
-
### Set up authentication
77
+
```bash
78
+
forrolein {retail.admin,editor,bigquery.admin}
79
+
do gcloud projects add-iam-policy-binding <YOUR_PROJECT_ID> --member="serviceAccount:<YOUR_SERVICE_ACCOUNT_ID>@<YOUR_PROJECT_ID>.iam.gserviceaccount.com" --role="roles/${role}"
80
+
done
81
+
```
75
82
76
-
To run a code sample from the Cloud Shell, you need to be authenticated using the service account credentials.
83
+
1. Use the following commandto show the service account email:
77
84
78
-
1. Login with your user credentials.
79
85
```bash
80
-
gcloud auth login
86
+
gcloud iam service-accounts list|grep <YOUR_SERVICE_ACCOUNT_ID>
81
87
```
82
88
83
-
1. Type `Y` and press **Enter**. Click the link in a Terminal. A browser window should appear asking you to log in using your Gmail account.
89
+
Copy the service account email.
84
90
85
-
1. Provide the Google Auth Library with access to your credentials and paste the code from the browser to the Terminal.
86
91
87
-
1. Upload your service account key JSON file and use it to activate the service account:
92
+
1. Upload your service account key JSON file and use it to activate the service
93
+
account:
88
94
89
95
```bash
90
96
gcloud iam service-accounts keys create ~/key.json --iam-account <YOUR_SERVICE_ACCOUNT_EMAIL>
@@ -94,57 +100,93 @@ To run a code sample from the Cloud Shell, you need to be authenticated using th
1. To request the Retail API, set your service account key JSON file as the GOOGLE_APPLICATION_CREDENTIALS environment variable :
103
+
1. Set the key as the GOOGLE_APPLICATION_CREDENTIALS environment variable to
104
+
use it for sending requests to the Retail API.
105
+
98
106
```bash
99
107
export GOOGLE_APPLICATION_CREDENTIALS=~/key.json
100
108
```
101
109
102
-
### Set the GOOGLE_CLOUD_PROJECT environment variable
110
+
### Google Cloud Retail libraries
111
+
112
+
Learn more about the [Java Google Cloud Retail library](https://googleapis.dev/java/google-cloud-retail/latest/index.html).
113
+
114
+
## Congrats! You have configured your work environment
103
115
104
-
You will run the code samples in your own Google Cloud project. To use the **project_id**inevery request to the Retail API, you should first specify them as environment variables.
116
+
1. Check that you arein the directory with code samples.
105
117
106
-
1. Find the project ID in the Project Info card displayed on **Home/Dashboard**.
118
+
The code samples foreach of the Retail services are storedin different directories.
119
+
120
+
Go to the code samples directory, your starting point to run more commands.
107
121
108
-
1. Set the **project_id** with the following command:
109
122
```bash
110
-
export GOOGLE_CLOUD_PROJECT=<YOUR_PROJECT_ID>
123
+
cd java-retail/samples/interactive-tutorials/
124
+
```
111
125
112
-
## Import Catalog Data
126
+
## Import catalog data
113
127
114
-
This step is required if this is the first Retail API Tutorial you run.
115
-
Otherwise, you can skip it.
128
+
<i>This step is required if this is the first Retail API tutorial that you run.
129
+
Otherwise, you can skip it.</i>
116
130
117
-
### Upload catalog data to Cloud Storage
131
+
There is a java-retail/samples/interactive-tutorials/src/main/resources/products.json file with valid products prepared in the `resources` directory.
118
132
119
-
There is a JSON file with valid products prepared in the `product` directory:
120
-
`product/resources/products.json`.
133
+
The other file, java-retail/samples/interactive-tutorials/src/main/resources/products_some_invalid.json, contains both valid and invalid products. You will use it to check the error handling.
121
134
122
-
Another file, `product/resources/products_some_invalid.json`, contains both valid and invalid products, and you will use it to check the error handling.
135
+
- If you want to **speed up the process**, run the following script in the Terminal directory to import all products to catalog and skip the next **Prepare the catalog data step-by-step** tutorial step:
123
136
124
-
In your own project, create a Cloud Storage bucket and put the JSON file there.
1. To create the bucket and upload the JSON file, open java-retail/samples/interactive-tutorials/src/main/java/product/setup/ProductsCreateGcsBucket.java file
159
+
160
+
1. Go to the **product** directory and run the following commandin the Terminal:
To import the prepared products to a catalog, open java-retail/samples/interactive-tutorials/src/main/java/product/ImportProductsGcs.java file and run the following commandin the Terminal:
0 commit comments