开发者

GoogleTransport class problem

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.go开发者_JS百科ogle.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?


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


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/).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜