Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google sheets AuthorizationCodeInstalledApp.Authorization(“用户”)。如何为每个用户获取唯一的userID?_Google Sheets_Google Api_Google Oauth - Fatal编程技术网

Google sheets AuthorizationCodeInstalledApp.Authorization(“用户”)。如何为每个用户获取唯一的userID?

Google sheets AuthorizationCodeInstalledApp.Authorization(“用户”)。如何为每个用户获取唯一的userID?,google-sheets,google-api,google-oauth,Google Sheets,Google Api,Google Oauth,我的应用程序的输入是一个谷歌工作表URL,它可以获取凭证并读取工作表的内容。 当我的应用程序使用Oauth2.0从用户那里获得授权时,我使用下面Google文档中的示例代码。对于每个用户,我想存储一个唯一的凭证,这样当一个用户多次请求我的应用程序时,我就不必每次都创建和存储新凭证(实际上这部分是在AuthorizationCodeInstalledApp(flow,receiver)中实现的。Authorization(“用户”),当“用户”没有凭证时,它将创建一个新凭证。 在示例代码中,我认为

我的应用程序的输入是一个谷歌工作表URL,它可以获取凭证并读取工作表的内容。 当我的应用程序使用Oauth2.0从用户那里获得授权时,我使用下面Google文档中的示例代码。对于每个用户,我想存储一个唯一的凭证,这样当一个用户多次请求我的应用程序时,我就不必每次都创建和存储新凭证(实际上这部分是在AuthorizationCodeInstalledApp(flow,receiver)中实现的。Authorization(“用户”),当“用户”没有凭证时,它将创建一个新凭证。 在示例代码中,我认为它不考虑当多个用户向应用程序发送请求时的情况,“用户”不能是多个用户的用户ID,因此“用户”必须对每个用户进行调整,这意味着它不能是常数。 由于凭据存储在本地,如果同一用户在短时间内多次请求,则用户不必重定向到Google登录页面来授予我的应用程序授权。 我的问题是,当多个用户调用我的端点时,我可以如何为每个不同的用户提供一个唯一的用户ID,每个用户都可以在短时间内输入多个url

我有一个想法,如果GoogleAPI有一种方法,它可以在获取凭证之前获取用户的唯一信息,比如userID的用户名

private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
    // Load client secrets.
    InputStream in = KirbyGsheet.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
    if (in == null) {
        throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
    }
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
            .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
            .setAccessType("offline")
            .build();
    LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(9998).build();
    return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}

我通过从前端提取用户信息来制作一个唯一的ID,然后将这个ID和url发送到后端来解决这个问题