简体   繁体   English

Android- Oauth 2.0谷歌登录

[英]Android- Oauth 2.0 google login

Need good and simple example of android app that requires login on google auth that I can use in my app. 需要Android应用程序的简单示例,该示例要求我可以在我的应用程序中使用的google auth登录。 I'm new to OAuth so I'm trying every example I get. 我是OAuth的新手,所以我正在尝试获得的每个示例。

I have already made autentication with facebook, got users name and all basic info. 我已经对Facebook进行了自定义,获得了用户名和所有基本信息。 On facebook I worked on this example: http://blog.doityourselfandroid.com/2011/02/28/30-minute-guide-integrating-facebook-android-application/ 在facebook上,我研究了以下示例: http : //blog.doityourselfandroid.com/2011/02/28/30-minute-guide-integrating-facebook-android-application/

But when I try from this example: http://blog.doityourselfandroid.com/2011/08/06/oauth-2-0-flow-android/ Registered app and imported project into eclipse over git just can't run. 但是,当我从以下示例尝试时: http : //blog.doityourselfandroid.com/2011/08/06/oauth-2-0-flow-android/注册的应用程序和通过git导入到eclipse中的项目都无法运行。 Followed everything step by step. 跟着一切一步步走。 Always getting error on JsonFactory. 总是在JsonFactory上出错。

code: 码:

private void performApiCall() {
    try {
        JsonFactory jsonFactory = new JacksonFactory();
        HttpTransport transport = new NetHttpTransport();

        CredentialStore credentialStore = new SharedPreferencesCredentialStore(prefs);
        AccessTokenResponse accessTokenResponse = credentialStore.read();

        GoogleAccessProtectedResource accessProtectedResource = new GoogleAccessProtectedResource(accessTokenResponse.accessToken,
                transport,
                jsonFactory,
                OAuth2ClientCredentials.CLIENT_ID,
                OAuth2ClientCredentials.CLIENT_SECRET,
                accessTokenResponse.refreshToken);

        final Latitude latitude = new Latitude(transport, accessProtectedResource, jsonFactory);
        latitude.apiKey=OAuth2ClientCredentials.API_KEY;

        LatitudeCurrentlocationResourceJson currentLocation = latitude.currentLocation.get().execute();
        String locationAsString = convertLocationToString(currentLocation);
        textView.setText(locationAsString);
    } catch (Exception ex) {
        ex.printStackTrace();
        textView.setText("Error occured : " + ex.getMessage());
    }
}

error code: 错误代码:

08-11 21:45:33.606: W/dalvikvm(464): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
08-11 21:45:33.606: E/AndroidRuntime(464): Uncaught handler: thread main exiting due to uncaught exception
08-11 21:45:33.606: E/AndroidRuntime(464): java.lang.NoClassDefFoundError: com.google.api.client.json.jackson.JacksonFactory
08-11 21:45:33.606: E/AndroidRuntime(464):  at com.ecs.android.sample.oauth2.LatitudeApiSample.performApiCall(LatitudeApiSample.java:79)
08-11 21:45:33.606: E/AndroidRuntime(464):  at com.ecs.android.sample.oauth2.LatitudeApiSample.onCreate(LatitudeApiSample.java:61)
08-11 21:45:33.606: E/AndroidRuntime(464):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-11 21:45:33.606: E/AndroidRuntime(464):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
08-11 21:45:33.606: E/AndroidRuntime(464):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
08-11 21:45:33.606: E/AndroidRuntime(464):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
08-11 21:45:33.606: E/AndroidRuntime(464):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
08-11 21:45:33.606: E/AndroidRuntime(464):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 21:45:33.606: E/AndroidRuntime(464):  at android.os.Looper.loop(Looper.java:123)
08-11 21:45:33.606: E/AndroidRuntime(464):  at android.app.ActivityThread.main(ActivityThread.java:4363)
08-11 21:45:33.606: E/AndroidRuntime(464):  at java.lang.reflect.Method.invokeNative(Native Method)
08-11 21:45:33.606: E/AndroidRuntime(464):  at java.lang.reflect.Method.invoke(Method.java:521)
08-11 21:45:33.606: E/AndroidRuntime(464):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-11 21:45:33.606: E/AndroidRuntime(464):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-11 21:45:33.606: E/AndroidRuntime(464):  at dalvik.system.NativeStart.main(Native Method)
08-11 21:45:33.616: I/dalvikvm(464): threadid=7: reacting to signal 3
08-11 21:45:33.616: E/dalvikvm(464): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

If someone know what is problem or can post some links of projects with source code and good explanation. 如果有人知道问题所在,或者可以发布一些带有源代码和良好解释的项目链接。

My app only need to login over google auth and get name of user. 我的应用程序只需要登录google auth并获取用户名。

You are missing a jar file in your project, it appears: 您在项目中缺少一个jar文件,它显示为:

java.lang.NoClassDefFoundError: com.google.api.client.json.jackson.JacksonFactory

So, you may want to find it from here: 因此,您可能想从这里找到它:

http://code.google.com/p/google-api-java-client/

If you have the library then you may just need to check the jar file to have it exported, and you can find a screenshot of how to do that in this answer: 如果您拥有该库,则可能只需要检查jar文件以将其导出,就可以在此答案中找到有关如何执行此操作的屏幕截图:

https://stackoverflow.com/a/9937414/67566 https://stackoverflow.com/a/9937414/67566

If you go to Configure Build Path then under the Order and Export tab, verify that the checkbox by your jar files are selected, and that may solve your problem. 如果转到“配置构建路径”,然后在“顺序和导出”选项卡下,请确认已选中jar文件旁边的复选框,这可能会解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM