未找到Android和Google客户端API NetHttptransport类

未找到Android和Google客户端API NetHttptransport类,第1张

概述我正在尝试首次使用Google生成的API库.我从SampleProgramprovidedbyGoogle中获取了代码.我的代码看起来像importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;importandroid.app.Activity;importandroid.os.Bundle;//Cor

我正在尝试首次使用Google生成的API库.我从Sample Program provided by Google中获取了代码.我的代码看起来像

import java.io.BufferedReader;import java.io.IOException;import java.io.inputStreamReader;import androID.app.Activity;import androID.os.Bundle;// Core Google Apiimport com.Google.API.clIEnt.auth.oauth2.draft10.AccesstokenResponse;import com.Google.API.clIEnt.GoogleAPIs.auth.oauth2.draft10.GoogleAccessprotectedResource;import com.Google.API.clIEnt.GoogleAPIs.auth.oauth2.draft10.GoogleAccesstokenRequest.GoogleAuthorizationCodeGrant;import com.Google.API.clIEnt.GoogleAPIs.auth.oauth2.draft10.GoogleAuthorizationRequestUrl;import com.Google.API.clIEnt.http.ByteArrayContent;import com.Google.API.clIEnt.http.GenericUrl;import com.Google.API.clIEnt.http.httpRequest;import com.Google.API.clIEnt.http.httpRequestFactory;import com.Google.API.clIEnt.http.httpResponse;import com.Google.API.clIEnt.http.httpTransport;import com.Google.API.clIEnt.http.javanet.NethttpTransport;import com.Google.API.clIEnt.Json.JsonFactory;import com.Google.API.clIEnt.Json.jackson.JacksonFactory;// Google+ APIimport com.Google.API.services.plus.*;public class GooglePlusActivity extends Activity {    // Want data about authenticated user    private static final String ScopE = "https://www.GoogleAPIs.com/auth/plus.me";    //    private static final String CALLBACK_URL = "urn:IEtf:wg:oauth:2.0:oob";    //    private static final httpTransport TRANSPORT = new NethttpTransport();    private static final JsonFactory JsON_FACTORY = new JacksonFactory();    private static final String CLIENT_ID = "XXXXXXXXXXXXXXX";    private static final String CLIENT_SECRET = "XXXXXXXXXXXXXX";    /** Called when the activity is first created. */    @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.main);        // Generate the URL to which we will direct users        String authorizeUrl = new GoogleAuthorizationRequestUrl(CLIENT_ID,                CALLBACK_URL, ScopE).build();        BufferedReader in = new BufferedReader(new inputStreamReader(system.in));        try {            String authorizationCode = in.readline();            // Exchange for an access and refresh token            GoogleAuthorizationCodeGrant authRequest = new GoogleAuthorizationCodeGrant(TRANSPORT,                JsON_FACTORY, CLIENT_ID, CLIENT_SECRET, authorizationCode, CALLBACK_URL);            authRequest.useBasicAuthorization = false;            AccesstokenResponse authResponse = authRequest.execute();            String accesstoken = authResponse.accesstoken;            GoogleAccessprotectedResource access = new GoogleAccessprotectedResource(accesstoken,                TRANSPORT, JsON_FACTORY, CLIENT_ID, CLIENT_SECRET, authResponse.refreshToken);            httpRequestFactory rf = TRANSPORT.createRequestFactory(access);            System.out.println("Access token: " + authResponse.accesstoken);        } catch (IOException e) {            // Todo auto-generated catch block            e.printstacktrace();        }        Plus plus = new Plus(new NethttpTransport(), new JacksonFactory());    }}

但是以下行:

private static final httpTransport TRANSPORT = new NethttpTransport();

导致异常:

10-04 13:33:28.954: ERROR/AndroIDRuntime(5925): Caused by: java.lang.NoClassDefFoundError: com.Google.API.clIEnt.http.javanet.NethttpTransport

我在构建路径中添加了以下库:

谷歌的API客户端-1.5.0-beta.jar
谷歌的API服务加v1-1.2.2-beta.jar

和这些依赖库:

番石榴-R09
httpClIEnt的-4.0.3
杰克逊核心ASL-1.6.7
GSON-1.6

我只是出于绝望而添加了依赖关系…因为我看不到我需要它们.我的所有import语句在编译时都能正确解析,为什么我会收到这个错误?

我在windows 7上使用Eclipse Indigo.

我添加了以下jar文件:

谷歌的API客户端-1.5.0-β
谷歌的API客户端的扩展-1.5.0-β
谷歌的API客户端的扩展,androID2-1.5.0-β
谷歌的API服务加v1-1.2.2-β
谷歌-http的客户端1.5.0测试版
谷歌-http客户端的扩展-1.5.0-β
谷歌-http客户端的扩展,androID2-1.5.0-β
谷歌-OAuth的客户端1.5.0测试版
谷歌-OAuth的客户扩展-1.5.0-β
GSON-1.6
番石榴-R09
httpClIEnt的-4.0.3
的httpCore-4.0.1
杰克逊核心ASL-1.6.7

这解决了我的问题.但是我仍然不确定这些文件如何与wiki页面上的库列表相对应,以及为什么在编译期间解析导入时需要它们.

解决方法:

您必须明确添加Google-http-clIEnt-1.5.0-beta.jar的库引用(右键单击项目 – >属性 – > Java构建路径 – >添加外部JAR),不要相信类路径.
如果不这样做,在apk文件中不包含所需的数据.
您可以从google-plus-java-starter_v5.zip下载Google plus库

总结

以上是内存溢出为你收集整理的未找到Android和Google客户端API NetHttptransport类全部内容,希望文章能够帮你解决未找到Android和Google客户端API NetHttptransport类所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1101114.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存