Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.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
使用Scala登录Google Oauth2会引发.setAccessType异常(“脱机”)_Scala_Google Drive Api_Google Api Java Client_Google Oauth - Fatal编程技术网

使用Scala登录Google Oauth2会引发.setAccessType异常(“脱机”)

使用Scala登录Google Oauth2会引发.setAccessType异常(“脱机”),scala,google-drive-api,google-api-java-client,google-oauth,Scala,Google Drive Api,Google Api Java Client,Google Oauth,我正在尝试获取刷新令牌,以便将文件批量上载到Google Drive。它适用于使用以下代码进行“在线”访问: val flow = new GoogleAuthorizationCodeFlow.Builder( httpTransport, jsonFactory, CLIENT_ID, CLIENT_SECRET, Arrays.asList(DriveScopes.DRIVE)) .setApprovalPrompt("auto") .set

我正在尝试获取刷新令牌,以便将文件批量上载到Google Drive。它适用于使用以下代码进行“在线”访问:

      val flow = new GoogleAuthorizationCodeFlow.Builder(
      httpTransport, jsonFactory, CLIENT_ID, CLIENT_SECRET, Arrays.asList(DriveScopes.DRIVE))
      .setApprovalPrompt("auto")
      .setAccessType("online")
      .build
但当我换成:

setAccessType("offline")
将引发此异常:

    Exception in thread "main" java.lang.IllegalArgumentException: Please use the Builder and call setJsonFactory, setTransport and setClientSecrets
at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:92)
at com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:49)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.setRefreshToken(GoogleCredential.java:221)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.setRefreshToken(GoogleCredential.java:158)
at com.google.api.client.auth.oauth2.Credential.setFromTokenResponse(Credential.java:540)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.setFromTokenResponse(GoogleCredential.java:240)
at google_uploader2$.delayedEndpoint$google_uploader2$1(google_uploader2.scala:82)
at google_uploader2$delayedInit$body.apply(google_uploader2.scala:1)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.App$class.main(App.scala:76)
at google_uploader2$.main(google_uploader2.scala:1)
at google_uploader2.main(google_uploader2.scala)
我真的找不到这个,任何建议都很感激。我尝试了
.setApprovalPrompt(“强制”)


谢谢,克莱德

谢谢,布布尔坦。下次我会尽量不那么草率。你试过按照错误消息所说的去做吗?pinoyyid-是的,尽管在我看来这些都是作为参数提供给GoogleAuthorizationCodeFlow.Builder构造函数的。正如我提到的,它对于“在线”访问非常有效。问题是我没有收到刷新令牌。我认为问题不在代码中。我刚刚试着运行来自GoogleAPI文档的java示例代码,它抛出了相同的异常。我认为这与应用程序有关,因为它存在于Google开发者的控制台上,但我没有发现任何与之相关的东西。值得发布代码,实现错误消息中的建议,以消除它。此外,您还意识到刷新令牌仅在第一次请求时返回。如果此用户已被授权,则可能值得取消授权以强制使用令牌,