我们正在尝试创建一个发布者主题,以提供一个发布/订阅频道,以便在新消息通过 REST 到达时得到通知。
我们正在使用两个 C# API V 1.35.1 和 Google PubSub V 1.0 Beta 20。
如果我们正在为开发者帐户注册 pub/sub,则此方法有效。但是,如果我们尝试使用标准帐户,它会失败。
要创建主题,我们有这些方法。
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 令牌并将其发送到我们的
服务器。 - 创建一个线程,我们的服务器使用
mobiles oauth 令牌通过 IMAP 连接。 - 使用 imap idle() 来侦听新的电子邮件事件。
我们正在尝试用基于 REST 的方法来替换这种设计。我们不想生成 100 个线程,每个线程都有一个开放的 IMAP 套接字。
根据您的回答,我们认为我们需要执行以下操作:
- 从项目所有者账户中,将每个客户的账户添加到我们的 IAM,角色为 Pub/Sub 订阅者
- 从最终用户帐户,使用 OAuth 凭据登录到 gmail-api,并每天调用“watch”以保持订阅处于活动状态。
这种方法的问题是:
- 我们正在创建一个 SAS 应用程序。用户不是我们组织的成员。
- 所有用户帐户都需要以 Pub/Sub 订阅者的角色添加到我们的组织 IAM
- 我们没有看到任何允许我们将用户添加到 IAM 的 api,我们必须通过控制台。
不确定我们在这里出错了。提前感谢您的反馈。