无法导入google.api.client等

时间:2019-02-08 06:28:48

标签: java google-api google-sheets-api google-api-java-client

首先,我正在尝试遵循此'https://developers.google.com/sheets/api/quickstart/java'。

但是复制此示例时,我无法运行它。 ;(

enter image description here

和我的pom.xml文件。

<!-- google-->
    <dependency>
        <groupId>com.google.api-client</groupId>
        <artifactId>google-api-client</artifactId>
        <version>1.28.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.oauth-client</groupId>
        <artifactId>google-oauth-client-jetty</artifactId>
        <version>1.28.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-sheets</artifactId>
        <version>v4-rev553-1.25.0</version>
    </dependency>
    <!-- google-->

如何遵循该示例? 我想使用Google表格。

env)spring-boot,java8

2 个答案:

答案 0 :(得分:0)

您是否尝试过重建项目?有时这会有所帮助。您可以尝试的另一种选择是更改版本。

    <!-- https://mvnrepository.com/artifact/com.google.api-client/google-api-client -->
<dependency>
    <groupId>com.google.api-client</groupId>
    <artifactId>google-api-client</artifactId>
    <version>1.23.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.oauth-client/google-oauth-client-jetty -->
<dependency>
    <groupId>com.google.oauth-client</groupId>
    <artifactId>google-oauth-client-jetty</artifactId>
    <version>1.23.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.apis/google-api-services-sheets -->
<dependency>
    <groupId>com.google.apis</groupId>
    <artifactId>google-api-services-sheets</artifactId>
    <version>v4-rev516-1.23.0</version>
</dependency>

答案 1 :(得分:0)

我尝试了几种方法。 最后,我创建了一个新的gradle项目,并成功导入了该项目。 因为gradle项目使用maven中央存储库。 因此,我比较了gradle项目和maven项目的依赖性。 我把它写在了maven pom.xml文件中。

这是我的pom.xml

<!-- google-->
    <dependency>
        <groupId>com.google.api-client</groupId>
        <artifactId>google-api-client</artifactId>
        <version>1.23.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.google.oauth-client/google-oauth-client-jetty -->
    <dependency>
        <groupId>com.google.oauth-client</groupId>
        <artifactId>google-oauth-client-jetty</artifactId>
        <version>1.23.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.google.apis/google-api-services-sheets -->
    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-sheets</artifactId>
        <version>v4-rev516-1.23.0</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/jetty/org.mortbay.jetty -->
    <!-- https://mvnrepository.com/artifact/jetty/org.mortbay.jetty -->
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty</artifactId>
        <version>6.1.26</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.mortbay.jetty/jetty-util -->
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-util</artifactId>
        <version>6.1.26</version>
    </dependency>

    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5-20081211</version>
    </dependency>

谢谢。