我正在尝试使用Apps脚本创建Google Hangouts Chat聊天机器人(在G Suite中)。我想获得聊天室中每个人的列表,但尚未在Apps Scripts中直接支持,因此我使用的是其余的API。 API调用list
似乎很简单:
命令是
GET https://chat.googleapis.com/v1/{parent=spaces/*}/members
我已经创建了一个授权服务帐户,然后使用
var endpoint = 'https://chat.googleapis.com/v1/{parent="spaces/pQkgxxxxxxx"}/members'
var options = {
method: "GET",
contentType : "application/json" ,
muteHttpExceptions : true,
headers: {
"Authorization": "Bearer " + goa.getToken(),
}
};
var response = UrlFetchApp.fetch(endpoint, options)`
我得到了
参数无效:https://chat.googleapis.com/v1/ {parent =“spaces / pQkgxxxxxxxx”} / members
我已经尝试编码parent
参数,但错误仍然存在。有任何想法吗?
根据您链接的页面上的官方文档,路径参数parent
的预期格式为spaces/*
。给出的示例值是spaces/AAAAMpdlehY
换句话说,即使模板URL,也不要写{parents=
和}
位。
GET
https://chat.googleapis.com/v1/{parent=spaces/*}/members
拥有它们。这个模板url格式在Google API HTTP annotation website上有详细解释。
在您的示例中,GET的正确URI是https://chat.googleapis.com/v1/spaces/pQkgxxxxxxx/members
您还应该考虑通过检查响应中的pQkgxxxxxxx
(并在下次调用中将其作为URL参数nextPageToken
传递),可能需要多次调用来解析空间pageToken
的所有成员。
您还应该考虑此查询返回的MemberShip
可能包含具有各种成员身份的成员。