创建Android的HTTP请求在谷歌的HTTP传输对象 [英] Creating a Google HTTP Transport Object for Android HTTP Request

查看:123
本文介绍了创建Android的HTTP请求在谷歌的HTTP传输对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个Android应用程序,并试图通过谷歌API客户端使用谷歌Places API的。我一直在下面这个例子:
http://ddewaele.blogspot.com/2011/05/introducing -Google-地方-api.html

I'm creating an Android app and trying to use Google Places API through Google APIs Client. I've been following this example: http://ddewaele.blogspot.com/2011/05/introducing-google-places-api.html

我在创建一个HTTP传输对象在创建HTTP请求工厂使用的问题。一切编译罚款在Eclipse中,但是当我调试我的手机上运行时,我在这里得到的第一行ClassNotFound的:

I'm having problems creating a HTTP Transport Object to use in creating the HTTP Request Factory. Everything compiles fine in eclipse, but when I debug while running on my phone, I get a classnotfound on the first line here:

HttpTransport transport = new ApacheHttpTransport();
HttpRequestFactory httpRequestFactory = createRequestFactory(transport);


public static HttpRequestFactory createRequestFactory(HttpTransport transport) {
    return transport.createRequestFactory(new HttpRequestInitializer() {
        @Override
        public void initialize(HttpRequest request) throws IOException {
            request.headers.authorization = "...";
        }
    });
}

据的JavaDoc为HTTP传输类:

According to the JavaDoc for the HTTP Transport Class:

Android的:


      
  • 与SDK 2.3开始,强烈建议使用
      com.google.api.client.javanet.NetHttpTransport。他们的Apache HTTP客户端
      实施没有得到很好的维护。

  •   
  • 对于SDK 2.2和更早版本,使用com.google.api.client.apache.ApacheHttpTransport。
      com.google.api.client.javanet.NetHttpTransport
      不推荐,因为一些错误的
      Android SDK的实施
      HttpURLConnection类。

  •   

我在2.2上运行的,所以我尝试使用ApacheHTTPTransport。我也尝试了NetHTTPTransport,但我得到同样的事情(ClassNotFound的)。

I'm running on 2.2, so I tried using the ApacheHTTPTransport. I've also tried the NetHTTPTransport, but I get the same thing (classnotfound).

任何想法/例子吗?

谢谢!

推荐答案

为了运行在使用谷歌API客户端在Android环境的地方API,你需要有以下的依赖在你的Andr​​oid项目:

In order to run the Places API in an Android environment using the Google APIs Client, you'll need to have the following dependencies in your Android project :


  • M2_REPO / commons- codeC / commons- codeC / 1.3 / commons- codeC-1.3.jar

  • M2_REPO /的commons-logging /的commons-logging / 1.1.1 /的commons-logging-1.1.1.jar

  • M2_REPO / COM /谷歌/ API /客户/谷歌API的客户端/ 1.4.1-β/谷歌的API客户端-1.4.1-beta.jar

  • M2_REPO/com/google/api/client/google-api-client-googleapis/1.4.1-beta/google-api-client-googleapis-1.4.1-beta.jar

  • M2_REPO / COM /谷歌/ code / GSON / GSON / 1.6 / GSON-1.6.jar

  • M2_REPO / COM /谷歌/番石榴/芭乐/ R08 /番石榴r08.jar

  • M2_REPO /组织/阿帕奇/ httpcomponents / HttpClient的/ 4.0.3 / HttpClient的-4.0.3.jar

  • M2_REPO /组织/阿帕奇/ httpcomponents /的HttpCore / 4.0.1 /的HttpCore-4.0.1.jar

  • M2_REPO /组织/ codehaus /杰克逊/杰克逊核心-ASL / 1.6.5 /杰克逊核心ASL-1.6.5.jar

  • M2_REPO / COM /谷歌/ code / FindBugs的/ JSR305 / 1.3.9 / jsr305-1.3.9.jar

这篇关于创建Android的HTTP请求在谷歌的HTTP传输对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆