使用Scala的Google Oauth2登录会引发.setAccessType异常(“离线”)

时间:2015-05-16 12:09:41

标签: scala google-drive-api google-api-java-client google-oauth2

我正在尝试获取刷新令牌,以将文件批量上传到Google云端硬盘。它适用于使用此代码进行“在线”访问:

      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("force")

谢谢,克莱德

0 个答案:

没有答案