Panduan memulai: Menggunakan library klien
Halaman ini menunjukkan cara memulai Food Ordering AI Agent API dalam bahasa pemrograman favorit Anda.
Sebelum memulai
- Login ke akun Google Cloud Anda. Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Food Ordering AI Agent API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart. - Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALSto the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Food Ordering AI Agent API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart. - Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALSto the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again.
Menginstal library klien
C#
Untuk informasi selengkapnya tentang menyiapkan lingkungan pengembangan C#, lihat Panduan Penyiapan Lingkungan Pengembangan C#.
Install-Package Google.Cloud.PubSub.V1 -Pre
Go
go get cloud.google.com/go/pubsub
Java
Untuk mengetahui informasi selengkapnya tentang cara menyiapkan lingkungan pengembangan Java, lihat Panduan Penyiapan Lingkungan Pengembangan Java.
Jika Anda menggunakan Maven, tambahkan kode berikut ke file pom.xml Anda: Untuk informasi lebih lanjut tentang
BOM, lihat BOM Library Google Cloud Platform.
Jika menggunakan Gradle, tambahkan kode berikut ke dependensi Anda:
Jika Anda menggunakan sbt, tambahkan kode berikut ke dependensi Anda:
Jika menggunakan Visual Studio Code atau IntelliJ, Anda dapat menambahkan library klien ke project menggunakan plugin IDE berikut:
Plugin menyediakan fungsi tambahan, seperti pengelolaan kunci untuk akun layanan. Lihat dokumentasi setiap plugin untuk mengetahui detailnya.
Node.js
Untuk mengetahui informasi selengkapnya tentang cara menyiapkan lingkungan pengembangan Node.js, lihat Panduan Penyiapan Lingkungan Pengembangan Node.js.
npm install @google-cloud/pubsub
PHP
composer require google/cloud-pubsub
Python
Untuk informasi selengkapnya tentang menyiapkan lingkungan pengembangan Python, lihat Panduan Penyiapan Lingkungan Pengembangan Python.
pip install --upgrade google-cloud-pubsub
Ruby
Untuk mengetahui informasi selengkapnya tentang cara menyiapkan lingkungan pengembangan Ruby, lihat Panduan Penyiapan Lingkungan Pengembangan Ruby.
gem install google-cloud-pubsub
Lakukan sesuatu
Sekarang Anda dapat menggunakan Food Ordering AI Agent untuk melakukan sesuatu. Jalankan kode berikut untuk melakukan sesuatu pertama Anda:
C#
Untuk melakukan autentikasi ke Agen AI Pemesanan Makanan, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Go
Untuk melakukan autentikasi ke Agen AI Pemesanan Makanan, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Java
Untuk melakukan autentikasi ke Agen AI Pemesanan Makanan, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Node.js
Untuk melakukan autentikasi ke Agen AI Pemesanan Makanan, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
PHP
Untuk melakukan autentikasi ke Agen AI Pemesanan Makanan, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Python
Untuk melakukan autentikasi ke Agen AI Pemesanan Makanan, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Ruby
Untuk melakukan autentikasi ke Agen AI Pemesanan Makanan, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Bagaimana hasilnya?
Pembersihan
Agar tidak menimbulkan biaya pada Akun Google Anda untuk resource yang digunakan dalam panduan memulai ini:
- Gunakan Google Cloud console untuk menghapus project Anda jika tidak lagi diperlukan.
Langkah berikutnya
Cari tahu lebih lanjut Library Klien API Agen AI Pemesanan Makanan kami.