Question

Need good and simple example of android app that requires login on google auth that I can use in my app. I'm new to OAuth so I'm trying every example I get.

I have already made autentication with facebook, got users name and all basic info. On facebook I worked on this example: 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. Followed everything step by step. Always getting error on 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.

Was it helpful?

Solution

You are missing a jar file in your project, it appears:

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:

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top