Steven Ferrino

Technical SEO / PHP Developer

  • Home
  • SEO
  • Local Search
  • PHP
You are here: Home / Google / Google Business Service Account API & PubSub

Google Business Service Account API & PubSub

March 10, 2025 by Steven Leave a Comment

pubsub

I spent a few hours trying to find information on using a service account with the getNotificationSetting() method, I am using Python, but it should work the same in Java, and C#. I told myself that when I got it figured out I had to document it to save someone else, like you, from a journey through many webpages, StackOverflow posts, Medium posts, and more. And here we are.

So….

What I found was that the updateMask isn’t looking for a straight on Text list of the different items you want to update in the PubSub, instead the updateMask only lets the API know what to expect in the body=[value]. This was different than I had done in the past which is why the script I initially used no longer worked.

You have 2 options for the update_mask:

  • pubsub_topic
  • notification_types

You can use 1 or both. For Example:

update_mask = “pubsub_topic, notification_types”

updateMask=update_mask,

body=updated_settings

service = create_oauth2_connection()
account_id = "99999999999999999999"

updated_settings = {}
pubsub_topic = "projects/riding-dragons-101/topics/reviews"
notification_types = [
"NEW_REVIEW",
"UPDATED_REVIEW",
"NEW_CUSTOMER_MEDIA",
"NEW_QUESTION",
"UPDATED_QUESTION",
"NEW_ANSWER",
"UPDATED_ANSWER",
"DUPLICATE_LOCATION"
]

currentList = service.accounts().getNotificationSetting(
name=f"accounts/{account_id}/notificationSetting"
).execute()

print("------------------ BEFORE ------------------------------------------")
print(currentList)
print("--------------------------------------------------------------------")

if True:
try:

updated_settings["pubsub_topic"] = pubsub_topic
updated_settings["notification_types"] = notification_types

## update_mask = "pubsub_topic,notification_types"
update_mask = "notification_types"

# https://github.com/googleapis/google-api-python-client/blob/main/googleapiclient/discovery_cache/documents/mybusinessnotifications.v1.json
updateList = service.accounts().updateNotificationSetting(
name=f"accounts/{account_id}/notificationSetting",
updateMask=update_mask,
body=updated_settings
).execute()

print("-------- UPDATE ------------")
print(f"UpdateList: {updateList} ")
except Exception as e:
print("\n\n------------------------ EXCEPTION -------------------------------")
print(f"Exception during updating: {e}")
print("------------------------------------------------------------------\n\n")

locationsList = service.accounts().getNotificationSetting(
name=f"accounts/{account_id}/notificationSetting"
).execute()

print("------------------ AFTER ------------------------------------------")
print(locationsList)
print("------------------------------------------------------------------")

# https://github.com/googleapis/google-api-python-client/blob/main/googleapiclient/discovery_cache/documents/mybusinessnotifications.v1.json

service = create_oauth2_connection()
account_id = “10116276071971111111111”

updated_settings = {}
pubsub_topic = “projects/dragon-training-160816/topics/reviews”
notification_types = [
“NEW_REVIEW”,
“UPDATED_REVIEW”,
“NEW_CUSTOMER_MEDIA”,
“NEW_QUESTION”,
“UPDATED_QUESTION”,
“NEW_ANSWER”,
“UPDATED_ANSWER”,
“DUPLICATE_LOCATION”
]

currentList = service.accounts().getNotificationSetting(
name=f”accounts/{account_id}/notificationSetting”
).execute()

print(“—————— BEFORE ——————————————“)
print(currentList)
print(“——————————————————————–“)

if True:
try:

updated_settings[“pubsub_topic”] = pubsub_topic
updated_settings[“notification_types”] = notification_types

update_mask = “pubsub_topic,notification_types”

updateList = service.accounts().updateNotificationSetting(
name=f”accounts/{account_id}/notificationSetting”,
updateMask=update_mask,
body=updated_settings
).execute()

print(“——– UPDATE ————“)
print(f”UpdateList: {updateList} “)
except Exception as e:
print(“\n\n———————— EXCEPTION ——————————-“)
print(f”Exception during updating: {e}”)
print(“——————————————————————\n\n”)

 

locationsList = service.accounts().getNotificationSetting(
name=f”accounts/{account_id}/notificationSetting”
).execute()

print(“—————— AFTER ——————————————“)
print(locationsList)
print(“——————————————————————“)

Filed Under: Google, Random

Steven Ferrino

Recent Posts

  • Google Business Service Account API & PubSub
  • Google Core March 2023 Not Just E-A-T
  • [Fix] – Jupiter Theme: /jupiter/dynamic-styles/global/header.php on line 346
  • Laravel 5.4: SQLSTATE[42000]: Password_resets – [Solution]
  • Restrict wp-login.php Access With Htaccess

Blogroll

  • Microdata Generator

Profiles

  • LinkedIn
  • Twitter

Copyright © 2025 · Dynamik-Gen on Genesis Framework · WordPress · Log in