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
* update README
* fix: sleep is added to the setup script
* fix: sleep is added to the setup script
Co-authored-by: tetiana-karasova <[email protected]>
Co-authored-by: Anthonios Partheniou <[email protected]>
Copy file name to clipboardExpand all lines: generated_samples/interactive-tutorials/README.md
+73-32Lines changed: 73 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -43,44 +43,69 @@ If, for some reason, you have decided to proceed with these code samples without
43
43
### Select your project and enable the Retail API
44
44
45
45
Google Cloud organizes resources into projects. This lets you
46
-
collect all the related resources for a single application in one place.
46
+
collect all related resources for a single application in one place.
47
47
48
48
If you don't have a Google Cloud project yet or you're not the owner of an existing one, you can
49
49
[create a new project](https://console.cloud.google.com/projectcreate).
50
50
51
-
After the project is created, set your PROJECT_ID to a ```project``` variable.
52
-
1. Run the following command in Terminal:
51
+
After the project is created, set your PROJECT_ID to a ```project``` variable:
52
+
53
+
1. Run the following command in the Terminal:
54
+
53
55
```bash
54
56
gcloud config set project <YOUR_PROJECT_ID>
55
57
```
56
58
57
-
1. To check that the Retail API is enabled for your Project, go to the [Admin Console](https://console.cloud.google.com/ai/retail/).
59
+
1. Ensure that the Retail API is enabled foryour projectin the [API & Services page](https://console.cloud.google.com/apis/api/retail.googleapis.com/).
60
+
61
+
1. Log in with your user credentials to run a code sample from the Cloud Shell:
62
+
63
+
```bash
64
+
gcloud auth login
65
+
```
66
+
67
+
1. Type `Y` and press **Enter**. Click the link in the Terminal. A browser window
68
+
should appear asking you to log in using your Gmail account.
69
+
70
+
1. Provide the Google Auth Library with access to your credentials and paste
71
+
the code from the browser to the Terminal.
72
+
73
+
## Prepare your work environment
74
+
75
+
To prepare the work environment you should perform the following steps:
76
+
- Create a service account.
77
+
- Create service account key and set it to authorize your calls to the Retail API.
78
+
- Install Google Cloud Retail library.
58
79
59
80
### Create service account
60
81
61
-
To access the Retail API, you must create a service account.
82
+
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).
62
83
63
-
1. To create a service account, follow this [instruction](https://cloud.google.com/retail/docs/setting-up#service-account)
84
+
1. To create a service account, perform the following command:
64
85
65
-
1. Find your service account on the [IAM page](https://console.cloud.google.com/iam-admin/iam),
66
-
click `Edit` icon, add the 'Storage Admin' and 'BigQuery Admin' roles. It may take some timefor changes to apply.
86
+
```bash
87
+
gcloud iam service-accounts create <YOUR_SERVICE_ACCOUNT_ID>
88
+
```
67
89
68
-
1. Copy the service account email in the Principal field.
90
+
1. Assign the needed roles to your service account:
1. To request the Retail API, set your service account key JSON file as the GOOGLE_APPLICATION_CREDENTIALS environment variable :
118
+
1. Set the key as the GOOGLE_APPLICATION_CREDENTIALS environment variable to
119
+
use it for sending requests to the Retail API.
120
+
94
121
```bash
95
122
export GOOGLE_APPLICATION_CREDENTIALS=~/key.json
96
123
```
@@ -100,12 +127,14 @@ To run a code sample from the Cloud Shell, you need to be authenticated using th
100
127
To run Python code samples for the Retail API tutorial, you need to set up your virtual environment.
101
128
102
129
1. Run the following commands in a Terminal to create an isolated Python environment:
130
+
103
131
```bash
104
-
pip install virtualenv
105
-
virtualenv myenv
132
+
virtualenv -p python3 myenv
106
133
source myenv/bin/activate
107
134
```
135
+
108
136
1. Next, install Google packages:
137
+
109
138
```bash
110
139
pip install google
111
140
pip install google-cloud-retail
@@ -114,41 +143,53 @@ To run Python code samples for the Retail API tutorial, you need to set up your
114
143
115
144
```
116
145
117
-
## Import Catalog Data
146
+
## Import catalog data
118
147
119
-
This step is required if this is the first Retail API Tutorial you run.
120
-
Otherwise, you can skip it.
148
+
There is a python-retail/samples/interactive-tutorials/resources/products.json file with valid products prepared in the `resources` directory.
149
+
150
+
The other file, python-retail/samples/interactive-tutorials/resources/products_some_invalid.json, contains both valid and invalid products. You will use it to check the error handling.
121
151
122
152
### Upload catalog data to Cloud Storage
123
153
124
-
There is a JSON file with valid products prepared inthe `product` directory:
125
-
`product/resources/products.json`.
154
+
In your own project you need to create a Cloud Storage bucket and put the JSON file there.
155
+
The bucket name must be unique. For convenience, you can name it `<YOUR_PROJECT_ID>_<TIMESTAMP>`.
126
156
127
-
Another file, `product/resources/products_some_invalid.json`, contains both valid and invalid products, and you will use it to check the error handling.
157
+
1. The code samples foreach of the Retail services are storedin different directories.
128
158
129
-
In your own project, create a Cloud Storage bucket and put the JSON file there.
130
-
The bucket name must be unique. For convenience, you can name it `<YOUR_PROJECT_ID>_<TIMESTAMP>`.
159
+
Go to the code samples directory, your starting point to run more commands.
131
160
132
-
1. To create the bucket and upload the JSON file, run the following commandin the Terminal:
161
+
```bash
162
+
cd python-retail/samples/interactive-tutorials
163
+
```
164
+
165
+
1. To create the bucket and upload the JSON file, open python-retail/samples/interactive-tutorials/product/setup_product/products_create_gcs_bucket.py file
166
+
167
+
1. Go to the **product** directory and run the following commandin the Terminal:
Now you can see the bucket is created in the [Cloud Storage](https://console.cloud.google.com/storage/browser), and the files are uploaded.
139
174
140
-
1. The name of the created Retail Search bucket is printed in the Terminal. Copy the name and set it as the environment variable `BUCKET_NAME`:
175
+
1. The name of the created Cloud Storage bucket is printed in the Terminal.
176
+
177
+
```
178
+
The gcs bucket <YOUR_PROJECT_ID>_<TIMESTAMP> was created
179
+
```
180
+
181
+
Copy the name and set it as the environment variable `BUCKET_NAME`:
141
182
142
183
```bash
143
184
export BUCKET_NAME=<YOUR_BUCKET_NAME>
144
185
```
145
186
146
187
### Import products to the Retail Catalog
147
188
148
-
To import the prepared products to a catalog, run the following commandin the Terminal:
189
+
To import the prepared products to a catalog, open python-retail/samples/interactive-tutorials/product/import_products_gcs.py file and run the following commandin the Terminal:
0 commit comments