需要良好且简单的 android 应用程序示例,该示例需要我可以在我的应用程序中使用的 google auth 登录。我是 OAuth 的新手,所以我正在尝试我得到的每个示例。
我已经用 facebook 进行了 autentication,得到了用户名和所有基本信息。在 facebook 我研究了这个例子:http ://blog.doityourselfandroid.com/2011/02/28/30-minute-guide-integrating-facebook-android-application/
但是当我从这个例子中尝试时:http://blog.doityourselfandroid.com/2011/08/06/oauth-2-0-flow-android/ 注册的应用程序和导入的项目通过 git 进入 Eclipse 只是无法运行。一步一步地跟随一切。JsonFactory 总是出错。
代码:
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());
}
}
错误代码:
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
如果有人知道什么是问题,或者可以发布一些带有源代码和良好解释的项目链接。
我的应用只需要通过 google auth 登录并获取用户名。