7
votes

this this code snniped:

  credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,//read from client secret.json file
                Scopes,
                "user",
                CancellationToken.None).Result;

   // Create Gmail API service.
   var service = new GmailService(new BaseClientService.Initializer()
   {
      HttpClientInitializer = credential,
      ApplicationName = ApplicationName,
   });

   UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");
   WatchRequest body = new WatchRequest()
        {
            TopicName = "projects/push-notifications-ver3/topics/mytopic",
            LabelIds = new[] {"INBOX"}
  string userId = "me";
  UsersResource.WatchRequest watchRequest = service.Users.Watch(body, userId);
  WatchResponse test = watchRequest.Execute();

Getting Error: Error sending test message to Cloud PubSub projects/push-notifications-ver3/topics/mytopic : User not authorized to perform this action. [403]

Topic was created with subscription, permission was given to current user as owner of topic Any suggestion why user not authorized ?

1
Make sure you also 'Grant publish rights on your topic'. I didn't do this step, and it results in authorization errors between the back end gmail service and the publisher endpoint. The topic basically only allows publishes to originate from authorized sources.Lo-Tan
@Dima Did you ever get this resolved? I just started using this feature and am facing the same issue.jpo
@Lo-Tan Do you please have a working example? I am also getting this error. I have given ownership permission to my service account.jpo
This looks like an issue that you'll probably need to report to the G Suite developers issue tracker at developers.googleblog.com/2017/03/…JL-HaiNan

1 Answers

0
votes

Have you completed the OAuth process for the given user? Also, are you replacing the word "user" in the method AuthorizeAsync() with your authenticated user? If yes, then try to do it with new client secrets file and also check if PubSub Scope is present in the variable scope.

I face a similar issue and it turned out to be one of these issues. Might work for you as well.