You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

技术咨询:是否有Google Chat Presence/Status用户状态相关API?

关于Google Workspace用户在线状态(Presence)的API实现方案

Google提供了官方API支持你所需的两个功能,基于Google Workspace服务完成:

1. 脚本更新自身在线状态

可以通过Google Chat API的Presence资源实现状态更新,步骤如下:

  • 启用Google Chat API并创建服务账号,配置OAuth 2.0权限(需chat.presences.update权限)
  • 调用接口提交状态参数,支持的availability值包括ONLINE、AWAY、BUSY等,还可设置自定义状态文本。

Python示例代码:

import google.auth
from googleapiclient.discovery import build

# 加载本地配置的OAuth凭据
creds, _ = google.auth.default(scopes=["https://www.googleapis.com/auth/chat.presences.update"])
chat_service = build('chat', 'v1', credentials=creds)

# 更新状态为忙碌并添加自定义说明
update_body = {
    "availability": "BUSY",
    "status": "正在处理任务,请勿打扰"
}
response = chat_service.users().me().presences().update(body=update_body).execute()
print("状态更新结果:", response)

2. 获取同事的在线状态

通过Google Chat API的Presence查询接口实现,需满足以下条件:

  • 申请chat.presences.read权限,且你与同事同属一个Google Workspace域名
  • 调用接口时传入同事的邮箱地址或Google Workspace用户ID作为user_id参数

Python示例代码:

import google.auth
from googleapiclient.discovery import build

creds, _ = google.auth.default(scopes=["https://www.googleapis.com/auth/chat.presences.read"])
chat_service = build('chat', 'v1', credentials=creds)

# 获取指定同事的状态(替换为实际邮箱)
user_email = "colleague@your-domain.com"
response = chat_service.users().presences().get(userId=user_email).execute()

# 解析状态信息
availability = response.get("availability")
status_text = response.get("status", "")
print(f"同事当前状态: {availability}, 自定义状态: {status_text}")

注意事项

  • 仅支持Google Workspace域名账号,个人Google账号无法使用这些API
  • 必须正确配置OAuth 2.0权限,确保脚本拥有对应读写权限
  • 操作频率需符合Google API配额限制,避免触发限流

内容的提问来源于stack exchange,提问作者EsseTi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 02:33:10