需要Android應用程序的良好和簡單的例子,需要登錄谷歌身份驗證,我可以在我的應用程序中使用。 我是OAuth的新手,所以我正在嘗試獲取每個示例。Android- Oauth 2.0谷歌登錄
我已經通過facebook進行了認證,獲得了用戶名和所有基本信息。 在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/ 註冊應用程序,並導入項目到Eclipse過了Git就不能運行。一切接着一切。總是在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
如果有人知道是什麼問題,也可以用後的源代碼,並很好的解釋項目的一些鏈接。
我的應用程序只需要通過谷歌身份驗證登錄並獲取用戶名。
爲什麼不顯示錯誤,也許你的代碼在錯誤發生的地方。 – 2012-08-11 21:31:52
編輯的問題,但我更喜歡另一個例子,因爲這一個不做我所需要的 – Jack 2012-08-11 21:51:36