在 Google 上的操作中获取用户 ID
Getting the userID in Actions on Google
在 Actions on Google site I find a function for getting the userID to identify a user across conversations and devices. In the docs section under getUser 上,我阅读了以下内容:
getUser() returns User
Gets the User object. The user object contains information about the
user, including a string identifier and personal information (requires
requesting permissions, see askForPermissions).
所以首先我需要请求许可。为此,我遵循 link。但是我发现只有三个权限可以请求。
- 姓名
- DEVICE_COARSE_LOCATION
- DEVICE_PRECISE_LOCATION
没有授予用户 ID 的权限。当我 运行 我的代码并尝试获取用户 ID 时,它 return 未定义。获取用户名工作正常。
function requestPermissonsIntent(app){
const permission = [app.SupportedPermissions.NAME];
app.askForPermission('Für eine korrekte Ausführung', permission);
}
//later in my code when asking for the userID and userName
if(app.isPermissionGranted()){
const userName = app.getUserName().displayName;
//getting the userName works fine
const userUID = app.getUser().userID;
//userUID is undefinded
...
如何获取用户 ID?
应该是小写"d"。
app.getUser().userId;
您无需请求任何权限即可获取此用户 ID。返回的字符串标识符在您的 Action 中对于该用户是唯一的。如果他们使用相同的帐户,它应该可以跨设备使用。
更新
自 2018 年 5 月起已弃用,计划于 2019 年 5 月停用。
如果您需要用户 ID,您有以下几种选择:
创建您自己的用户 ID 并将其保存在 user storage 对象中,该对象将在对话之间持续存在。 (不过,用户可以随时清空此存储空间。)
使用 Google Sign In for Assistant,每次调用您的 webhook 时,用户都会授权您获取他们的 Google ID 以及其他个人资料信息。
在 Actions on Google site I find a function for getting the userID to identify a user across conversations and devices. In the docs section under getUser 上,我阅读了以下内容:
getUser() returns User
Gets the User object. The user object contains information about the user, including a string identifier and personal information (requires requesting permissions, see askForPermissions).
所以首先我需要请求许可。为此,我遵循 link。但是我发现只有三个权限可以请求。
- 姓名
- DEVICE_COARSE_LOCATION
- DEVICE_PRECISE_LOCATION
没有授予用户 ID 的权限。当我 运行 我的代码并尝试获取用户 ID 时,它 return 未定义。获取用户名工作正常。
function requestPermissonsIntent(app){
const permission = [app.SupportedPermissions.NAME];
app.askForPermission('Für eine korrekte Ausführung', permission);
}
//later in my code when asking for the userID and userName
if(app.isPermissionGranted()){
const userName = app.getUserName().displayName;
//getting the userName works fine
const userUID = app.getUser().userID;
//userUID is undefinded
...
如何获取用户 ID?
应该是小写"d"。
app.getUser().userId;
您无需请求任何权限即可获取此用户 ID。返回的字符串标识符在您的 Action 中对于该用户是唯一的。如果他们使用相同的帐户,它应该可以跨设备使用。
更新
自 2018 年 5 月起已弃用,计划于 2019 年 5 月停用。
如果您需要用户 ID,您有以下几种选择:
创建您自己的用户 ID 并将其保存在 user storage 对象中,该对象将在对话之间持续存在。 (不过,用户可以随时清空此存储空间。)
使用 Google Sign In for Assistant,每次调用您的 webhook 时,用户都会授权您获取他们的 Google ID 以及其他个人资料信息。