Di Google My Business API, notifikasi dipublikasikan di layanan Cloud Pub/Sub. Setelah menyiapkan Cloud Pub/Sub dan membuat topik, Anda dapat melakukan tindakan berikut pada notifikasi:
Ulasan dan tanya jawab terkini atau yang diperbarui, media yang diupload, update Google untuk ulasan, perubahan status lokasi, dan lainnya didukung. Objek NotificationType mendeskripsikan dan menampilkan daftar jenis notifikasi yang tersedia.
Sebelum memulai
Untuk menggunakan Google My Business API, daftarkan aplikasi Anda dan dapatkan kredensial OAuth 2.0. Untuk mengetahui detail tentang cara memulai API, lihat Penyiapan dasar.
Penyiapan Cloud Pub/Sub
Untuk menyiapkan notifikasi Google My Business API dengan Cloud Pub/Sub, lakukan langkah-langkah berikut:
- Ikuti panduan Cloud Pub/Sub untuk menyiapkan aplikasi Anda.
- Buat topik di project Cloud Pub/Sub dan catat nama topik yang dibuat.
- Berikan setidaknya izin
pubsub.topics.publish
untuk mybusiness-api-pubsub@system.gserviceaccount.com. - Ikuti panduan Ringkasan subscriber untuk menyiapkan notifikasi push atau pull.
- Untuk menerima notifikasi, panggil
endpoint
accounts.updateNotifications
di Google My Business API. Pada panggilan, gunakan nama topik yang Anda buat di Cloud Pub/Sub untuk menautkan akun Bisnisku milik Anda ke topik tersebut. - (Opsional) Ulangi langkah 5 untuk setiap akun Google Bisnisku yang notifikasinya ingin Anda terima.
Mengambil setelan notifikasi
Endpoint accounts.getNotifications
menampilkan setelan notifikasi Cloud Pub/Sub saat ini untuk
akun. Tabel berikut menunjukkan cara memanggil endpoint tersebut di HTTP dan Java:
GET https://mybusiness.googleapis.com/v4/accounts/{accountId}/notifications
Fungsi berikut menggunakan Mybusiness.Accounts.getNotifications
dalam menampilkan data
untuk notifikasi akun.
/** * Demonstrates getting notification data. * @param name The name (account/`account_id`/notifications) for the notification to retrieve. * @return response The notification data. */ private static GetNotifications getNotifications(String name) throws Exception { Mybusiness.Accounts.getNotifications sub = mybusiness.accounts().getNotifications(name); GetNotifications response = sub.execute(); return response; }
Mengubah setelan notifikasi
Endpoint accounts.updateNotifications
memperbarui setelan notifikasi Cloud Pub/Sub yang terkait dengan
akun. Tabel berikut menunjukkan cara memanggil endpoint tersebut di HTTP dan Java:
PUT https://mybusiness.googleapis.com/v4/accounts/{accountId}/notifications { name: your/pubsub/topicName }
Fungsi berikut menggunakan Mybusiness.Accounts.Locations.Reviews.Get
.
/** * Demonstrates getting a review by name. * @param reviewName The name (resource path) of the review to retrieve. * @return Account The requested review. */ private static Review getReview(String reviewName) throws Exception { Mybusiness.Accounts.Locations.Reviews.Get review = mybusiness.accounts().locations().reviews().get(reviewName); Review response = review.execute(); return response; }
Menghapus setelan notifikasi
Endpoint accounts.deleteNotifications
menghapus setelan notifikasi Cloud Pub/Sub dari akun.
Tabel berikut menunjukkan cara memanggil endpoint tersebut di HTTP dan Java:
DELETE https://mybusiness.googleapis.com/v4/accounts/{accountId}/notifications
Fungsi berikut menggunakan Mybusiness.Accounts.DeleteNotifications
.
/** * Demonstrates deleting the Google Cloud Pub/Sub settings. * @param notificationName The name (account/`account_id`/notifications) for the notification settings to delete. * @return The deleted notification setting. */ private static DeleteNotifications deleteNotifications(String notificationName) throws Exception { Mybusiness.Accounts.DeleteNotifications toDelete = mybusiness.accounts().deleteNotifications(notificationName); DeleteNotification response = toDelete.execute(); return response; }