尝试验证访问令牌时,JsonObjectParser中的Google Drive Api错误

时间:2014-04-10 15:15:08

标签: oauth-2.0 google-drive-api google-api-java-client google-oauth-java-client

我正在尝试验证驱动器中的访问令牌:

GoogleCredential credential = new GoogleCredential.Builder()
    .setClientSecrets(clientId , clientSecret)
    .setTransport(TRANSPORT)
    .setJsonFactory(JSON_FACTORY)
    .build();

credential.setAccessToken(accessToken);

Drive service = new Drive.Builder(TRANSPORT, JSON_FACTORY, credential).build();

但我在最后一行收到错误

Caused by: java.lang.NoSuchMethodError: com.google.api.client.json.JsonObjectParser.  <init>(Lcom/google/api/client/json/JsonObjectParser$Builder;)V
[INFO]  at  com.google.api.client.json.JsonObjectParser$Builder.build(JsonObjectParser.java:163) ~  [google-http-client-1.17.0-rc.jar:1.11.0-beta]
[INFO]  at  com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient$Builder.<init> (AbstractGoogleJsonClient.java:74) ~[google-api-client-1.17.0-rc.jar:1.17.0-rc]
[INFO]  at com.google.api.services.drive.Drive$Builder.<init>(Drive.java:9177) ~[google-api-services-drive-v2-rev119-1.18.0-rc.jar:na]

我有以下库

<!--  JSON -->
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.1.3</version>
    </dependency>

    <dependency>
        <groupId>com.google.http-client</groupId>
        <artifactId>google-http-client-gson</artifactId>
        <version>1.18.0-rc</version>
    </dependency>
    <dependency>
        <groupId>com.google.http-client</groupId>
        <artifactId>google-http-client-jackson</artifactId>
        <version>1.18.0-rc</version>
    </dependency>


<!-- Google Api Drive  v2-rev9-1.8.0-beta -->
    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-drive</artifactId>
        <version>v2-rev120-1.18.0-rc</version>
    </dependency>

    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-oauth2</artifactId>
        <version>v2-rev66-1.17.0-rc</version>
    </dependency>


    <!-- Google Api Dependencies -->
    <dependency>
      <groupId>com.google.api-client</groupId>
      <artifactId>google-api-client</artifactId>
      <version>1.18.0-rc</version>
    </dependency>   
    <dependency>
        <groupId>com.google.oauth-client</groupId>
        <artifactId>google-oauth-client-servlet</artifactId>
        <version>1.18.0-rc</version>
    </dependency>
    <dependency>
        <groupId>com.google.http-client</groupId>
        <artifactId>google-http-client</artifactId>
        <version>1.18.0-rc</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>jsr305</artifactId>
        <version>1.3.9</version>
    </dependency>

    <!-- Google App Engine Dependencies  -->
     <dependency>
      <groupId>com.google.api-client</groupId>
      <artifactId>google-api-client-servlet</artifactId>
      <version>1.18.0-rc</version>
    </dependency>
    <dependency>
      <groupId>com.google.api-client</groupId>
      <artifactId>google-api-client-appengine</artifactId>
      <version>1.18.0-rc</version>
    </dependency>
    <dependency>
        <groupId>com.google.oauth-client</groupId>
        <artifactId>google-oauth-client-appengine</artifactId>
        <version>1.18.0-rc</version>
    </dependency>
    <dependency>
        <groupId>com.google.http-client</groupId>
        <artifactId>google-http-client-appengine</artifactId>
        <version>1.18.0-rc</version>
    </dependency>

我尝试更改不同版本的库,但同样的错误仍然存​​在。那么,错误是什么?我们错过了一些图书馆吗?

2 个答案:

答案 0 :(得分:0)

你在使用这个库吗?

  

谷歌-HTTP-客户jackson2-1.17.0-rc.jar

你可以找到它here

答案 1 :(得分:0)

我得到了同样的错误。通过在pom.xml中更新驱动器api库的版本来修复它。 那你应该打电话给

mvn clean package

您可以在Maven存储库中找到最新版本的Google库:

http://mvnrepository.com/artifact/com.google.apis/google-api-services-drive