javagoogle-cloud-pubsubgoogle-my-business-apigoogle-my-business

How to set pubsubTopic to get rid of SHARES_PUBSUB_TOPIC_MESSAGE_ACROSS_VERSIONS while using mybusinessnotifications.googleapis.com in java


I want to read a list of notifications which google returns for a specific account. It seems that my old program is not working, and I cannot find an example for the new API. First, we need to set what type of notifications we are interested in.Let's suppose mybusiness is an initializer of type MyBusinessNotificationSettings which also takes care of credentials:

 public void setNotificationTypes(String accountId, String projectId) {
        try {
            List<String> notificationTypes = Arrays.asList(
                    "GOOGLE_UPDATE", "NEW_REVIEW", "UPDATED_REVIEW", "NEW_QUESTION",
                    "UPDATED_QUESTION", "NEW_ANSWER", "UPDATED_ANSWER"
                    );

            GetNotificationSetting getSettings = mybusiness.accounts().getNotificationSetting(accountId+"/notificationSetting");
            NotificationSetting currentSettings = getSettings.execute();
            
 

            String pubSubTopic = "projects/"+projectId+"/topics/newNotification";

            currentSettings.setNotificationTypes(notificationTypes).setPubsubTopic(pubSubTopic);
            UpdateNotificationSetting updateRequest = mybusiness.accounts().
                    updateNotificationSetting(accountId + "/notificationSetting", currentSettings).setUpdateMask("pubsub_topic,notification_types");
            
            NotificationSetting updatedSettings = updateRequest.execute();


            System.out.println("Notification settings updated: " + updatedSettings);

        } catch (Exception e) {
            e.printStackTrace();
            
        }
    }

The Error is

POST https://mybusinessnotifications.googleapis.com/v1/accounts/XXXXXXXXXXXX/notificationSetting?updateMask=pubsub_topic,notification_types { "code" : 400, "details" : [ { "@type" : "type.googleapis.com/google.rpc.ErrorInfo", "reason" : "SHARES_PUBSUB_TOPIC_MESSAGE_ACROSS_VERSIONS" } ], "errors" : [ { "domain" : "global", "message" : "Request contains an invalid argument.", "reason" : "badRequest" } ], "message" : "Request contains an invalid argument.", "status" : "INVALID_ARGUMENT" }

How can I handle SHARES_PUBSUB_TOPIC_MESSAGE_ACROSS_VERSIONS problem? I have checked the permissions are all correct and the notifications topic exists, I even tried to create a new topic but the result did no change.

Has anyone worked with this API who can kindly give me a hand please?


Solution

  • I found out the response, I needed to create a new pub/sub topic with the new name: Creating new pub/sub topic

    and then going to cloud shell: cloud shell

    Assign the permission

    gcloud config set project ‘project_id’ enter image description here

    Finally, we should give at least pubsub.topics.publish permissions to mybusiness-api-pubsub@system.gserviceaccount.com. if you do not have already, create it by clicking on the Add Entities button

    enter image description here