Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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 apps script 调用Google API时检测访问令牌过期_Google Apps Script_Google Oauth - Fatal编程技术网

Google apps script 调用Google API时检测访问令牌过期

Google apps script 调用Google API时检测访问令牌过期,google-apps-script,google-oauth,Google Apps Script,Google Oauth,我有一个作为API可执行文件部署的Google应用程序脚本。我可以从基于java的web应用程序中调用它。但是,只有在执行该操作需要授权的情况下,才会失败。我做了分析,发现它失败了,因为如果访问令牌过期时间小于6分钟,应用程序脚本将返回此错误。应用程序脚本的这种行为背后有一个原因,这超出了这个问题的范围。但是,如果过期时间小于6分钟,解决方案是生成一个新的access\u令牌 我正在使用Java Google客户端库来管理访问令牌: GoogleCredential credential = n

我有一个作为API可执行文件部署的Google应用程序脚本。我可以从基于java的web应用程序中调用它。但是,只有在执行该操作需要授权的情况下,才会失败。我做了分析,发现它失败了,因为如果访问令牌过期时间小于6分钟,应用程序脚本将返回此错误。应用程序脚本的这种行为背后有一个原因,这超出了这个问题的范围。但是,如果过期时间小于6分钟,解决方案是生成一个新的
access\u令牌

我正在使用Java Google客户端库来管理访问令牌:

GoogleCredential credential = new GoogleCredential.Builder()
                                    .setTransport(httpTransport)
                                    .setJsonFactory(jsonFactory)
                                    .setClientSecrets("<<clientId>>", "<<clientSecret>>")
                                    .build();
credential.setRefreshToken("<<refresh_token>>");
调用应用程序脚本:

scriptService.scripts().run("test script");
客户端库负责生成访问令牌,将其存储在内存中,并在到期时调用OAuth API生成新令牌

现在,我需要你的建议:

  • 检查访问令牌的过期时间是否小于6分钟
  • 如果是,则生成新的访问令牌

  • 以下是查找令牌过期的剩余时间并生成新访问令牌的代码:

    检查访问令牌的过期时间是否小于6分钟

    如果是,则生成新的访问令牌


    以下是查找令牌过期的剩余时间并生成新访问令牌的代码:

    检查访问令牌的过期时间是否小于6分钟

    如果是,则生成新的访问令牌


    web服务器oauth客户端库有类似的功能吗?web服务器oauth客户端库有类似的功能吗?
    scriptService.scripts().run("test script");
    
    credential.getExpiresInSeconds()
    
    credential.refreshToken()