GoogleTransport 类问题

发布于 2024-12-02 08:59:23 字数 2302 浏览 0 评论 0 原文

我正在使用具有以下依赖项的 Maven 项目:

<dependency>
      <groupId>com.google.api.client</groupId>
      <artifactId>google-api-client-googleapis-auth-clientlogin</artifactId>
      <version>1.2.3-alpha</version>
    </dependency>

当我运行以下代码时:

import java.io.IOException;

import com.google.api.client.googleapis.GoogleTransport;
import com.google.api.client.googleapis.auth.clientlogin.ClientLogin;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.HttpTransport;
/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws IOException
    {
         HttpTransport transport = GoogleTransport.create();
           // transport.addParser(new JsonCParser());
            try {
              // authenticate with ClientLogin
              ClientLogin authenticator = new ClientLogin();
              authenticator.authTokenType = "ndev";
              authenticator.username = "....";
              authenticator.password = "....";
              authenticator.authenticate().setAuthorizationHeader(transport);
              // make query request
              HttpRequest request = transport.buildGetRequest();
              request.setUrl("https://www.googleapis.com/bigquery/v1/query");
              request.url.put(
                  "q", "select count(*) from [bigquery/samples/shakespeare];");
              System.out.println(request.execute().parseAsString());
            } catch (HttpResponseException e) {
              System.err.println(e.response.parseAsString());
              throw e;
            }

    }
}

我得到以下异常:

Exception in thread "main" java.lang.IllegalStateException: Missing required low-level HTTP transport package.
Use package "com.google.api.client.javanet".
    at com.google.api.client.http.HttpTransport.useLowLevelHttpTransport(HttpTransport.java:129)
    at com.google.api.client.http.HttpTransport.<init>(HttpTransport.java:187)
    at com.google.api.client.googleapis.GoogleTransport.create(GoogleTransport.java:58)
    at com.example.clientlogin.App.main(App.java:18)

GoogleTransport 类有什么问题?

i'm using a maven project with following dependency :

<dependency>
      <groupId>com.google.api.client</groupId>
      <artifactId>google-api-client-googleapis-auth-clientlogin</artifactId>
      <version>1.2.3-alpha</version>
    </dependency>

when i run following code:

import java.io.IOException;

import com.google.api.client.googleapis.GoogleTransport;
import com.google.api.client.googleapis.auth.clientlogin.ClientLogin;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.HttpTransport;
/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws IOException
    {
         HttpTransport transport = GoogleTransport.create();
           // transport.addParser(new JsonCParser());
            try {
              // authenticate with ClientLogin
              ClientLogin authenticator = new ClientLogin();
              authenticator.authTokenType = "ndev";
              authenticator.username = "....";
              authenticator.password = "....";
              authenticator.authenticate().setAuthorizationHeader(transport);
              // make query request
              HttpRequest request = transport.buildGetRequest();
              request.setUrl("https://www.googleapis.com/bigquery/v1/query");
              request.url.put(
                  "q", "select count(*) from [bigquery/samples/shakespeare];");
              System.out.println(request.execute().parseAsString());
            } catch (HttpResponseException e) {
              System.err.println(e.response.parseAsString());
              throw e;
            }

    }
}

i get below exception:

Exception in thread "main" java.lang.IllegalStateException: Missing required low-level HTTP transport package.
Use package "com.google.api.client.javanet".
    at com.google.api.client.http.HttpTransport.useLowLevelHttpTransport(HttpTransport.java:129)
    at com.google.api.client.http.HttpTransport.<init>(HttpTransport.java:187)
    at com.google.api.client.googleapis.GoogleTransport.create(GoogleTransport.java:58)
    at com.example.clientlogin.App.main(App.java:18)

what is the problem with GoogleTransport class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嗳卜坏 2024-12-09 08:59:23

快速谷歌搜索导致 maven for com.google.api.client.javanet.nethttpresponse 尝试将

<dependency>
    <groupId>com.google.api.client</groupId>
    <artifactId>google-api-client</artifactId>
    <version>1.2.3-alpha</version>
  </dependency>

<dependency>
    <groupId>com.google.api.client</groupId>
    <artifactId>google-api-client-javanet</artifactId>
    <version>1.2.3-alpha</version>
  </dependency>

添加到您的 POM 文件中

Quick googeling resulted in maven for com.google.api.client.javanet.nethttpresponse Try adding

<dependency>
    <groupId>com.google.api.client</groupId>
    <artifactId>google-api-client</artifactId>
    <version>1.2.3-alpha</version>
  </dependency>

or

<dependency>
    <groupId>com.google.api.client</groupId>
    <artifactId>google-api-client-javanet</artifactId>
    <version>1.2.3-alpha</version>
  </dependency>

to your POM file

当爱已成负担 2024-12-09 08:59:23

这个问题已经很老了,但我已经为我们的 Java Google Client Lib + BigQuery 示例添加了一些更新(此处:http://code.google.com/p/google-bigquery-tools/source/browse/samples/java/gettingstarted/BigQueryJavaGettingStarted/)。

this question is pretty old, but I've added some updates to our Java Google Client Lib + BigQuery samples (here: http://code.google.com/p/google-bigquery-tools/source/browse/samples/java/gettingstarted/BigQueryJavaGettingStarted/).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文