创建发布者主题时,“用户无权执行此操作”

时间:2018-08-22 00:09:05

标签: gmail-api google-cloud-pubsub google-iam

我们正在尝试创建一个发布者主题,以提供一个发布/订阅频道,以便在通过REST收到新消息时得到通知。

我们正在使用两个C#API V 1.35.1和Google PubSub V 1.0 Beta20。

如果我们正在为开发者帐户注册发布/订阅,则此方法有效。但是,如果我们尝试使用标准帐户,它将失败。

要创建主题,我们有以下方法。

 public PublisherServiceApiClient GetPublisher()
 {
            GoogleCredential cred = GoogleCredential.FromAccessToken(GmailCredentials.Token.AccessToken);
            Channel channel = new Channel(PublisherServiceApiClient.DefaultEndpoint.Host,
                PublisherServiceApiClient.DefaultEndpoint.Port, cred.ToChannelCredentials());

            var settings = PublisherServiceApiSettings.GetDefault();
            return PublisherServiceApiClient.Create(channel, settings);
}

public Topic CreateTopic()
{ 
            var publisherService = GetPublisher();

            var topicName = new TopicName(GmailProjectId, GMailVenueTopic);
            Topic topic = publisherService.CreateTopic(topicName);
            return topic;

}

失败发生在:

publisherService.CreateTopic(topicName); 

Grp.Core.RpcExcetion

和消息:

“Status(StatusCode=PermissionDenied, Detail="User not authorized to perform this action.")”

这些是我们使用gmail身份验证api通过oauth登录时请求的权限。

GoogleWebAuthorizationBroker.AuthorizeAsync

这些是添加的范围

public string GmailScopes => "https://mail.google.com/ " +
 "https://www.googleapis.com/auth/gmail.compose " +
 "https://www.googleapis.com/auth/gmail.insert " +
 "https://www.googleapis.com/auth/gmail.modify " +
 "https://www.googleapis.com/auth/gmail.send " +
 "https://www.googleapis.com/auth/gmail.labels " +
 "https://www.google.com/m8/feeds/ " +
 "https://www.googleapis.com/auth/contacts" +
 "https://www.googleapis.com/auth/contacts.readonly " +
 "https://www.googleapis.com/auth/admin.directory.user " +
 "https://www.googleapis.com/auth/admin.directory.group.member " +
 "https://www.googleapis.com/auth/admin.directory.group " +                                     
 "https://www.googleapis.com/auth/gmail.readonly " +
 "https://www.googleapis.com/auth/cloud-platform " +
 "profile " + "email";

问:当我们使用标准帐户而不是开发人员帐户时,是否需要缺少范围?

问:这可能与C#API处于测试版有关吗?

注意:这些是其他注释----------------------------------------- -

让我解释一下我们要做什么。要确保我们采用的方法与Gmail API提供的方法兼容?

当前,我们有一个具有以下工作流程的服务器应用程序:

  • 要求移动设备获取其oauth令牌并将其发送给我们
    服务器。
  • 使用
    创建一个线程,使我们的服务器通过IMAP连接到服务器 手机oauth令牌。
  • 使用imap idle()侦听新的电子邮件事件。

我们正在尝试使用基于REST的方法来替换此设计。我们不希望产生100个线程,每个线程都有一个开放的IMAP套接字。

根据您的回答,我们认为我们将需要执行以下操作:

  • 从项目所有者帐户中,将每个客户的帐户添加到我们的 具有发布/订阅订阅者角色的IAM
  • 从最终用户帐户中,使用OAuth登录到gmail-api 凭据并每天致电“观看”以保持订阅 活跃。

此方法的问题是:

  • 我们正在创建SAS应用程序。用户不是我们的成员 组织。
  • 所有用户帐户都需要添加到我们的组织中 具有发布/订阅订阅者角色的IAM
  • 我们看不到任何允许我们将用户添加到IAM的API,我们必须 进入控制台。

不确定我们在这里出错了。预先感谢您的反馈。

1 个答案:

答案 0 :(得分:0)

当我尝试将消息推送到Google Pub / Sub时,我遇到了同样的问题。我通过在Pub/Sub Admin部分的成员中添加IAM角色来解决此问题。

相关问题