Back to project page DaumOAuthSDKAndroidSample.
The source code is released under:
MIT License
If you think the Android project DaumOAuthSDKAndroidSample listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package net.daum.mf.sample.oauth; // www . ja v a 2s . c o m import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import net.daum.mf.oauth.MobileOAuthLibrary; import net.daum.mf.oauth.OAuthError; import net.daum.mf.oauth.impl.Logging; public class MainActivity extends Activity { static final String CLIENT_ID = "17947856"; TextView logText; /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { Log.e("", "onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.main); MobileOAuthLibrary.getInstance().initialize(this, CLIENT_ID); // OAuth ????????? ???. Logging.DEBUG = true; logText = (TextView) findViewById(R.id.tv_log); Button verify = (Button) findViewById(R.id.verify); verify.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // access token ????. MobileOAuthLibrary.getInstance().authorize(MainActivity.this, oAuthListener); } }); Button profile = (Button) findViewById(R.id.profile); profile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { LoadingIndicator.getInstance().startLoadingIndicator(MainActivity.this, null, "Profile API loading", false, null); // oauth 2.0 ??? ????? profile API ???? MobileOAuthLibrary.getInstance().requestResourceWithPath(getApplicationContext(), oAuthListener, "/user/v1/show.json"); } }); Button expire = (Button) findViewById(R.id.expire); expire.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // access token ??????. MobileOAuthLibrary.getInstance().expireAuthorization(); if (MobileOAuthLibrary.getInstance().isAuthorized()) { logText.append("expire fail"); } else { logText.append("expire success"); } } }); // ????? ??? Activity? ??? ??? ?? ?????? ?????. Uri uri = getIntent().getData(); if (uri != null) { Log.e("", "url : " + uri); // authorize() ?? ??? url scheme??? ?? callback??? ????. MobileOAuthLibrary.getInstance().handleUrlScheme(uri); } } @Override protected void onNewIntent(Intent intent) { Log.e("", "onNewIntent"); super.onNewIntent(intent); Uri uri = intent.getData(); if (uri != null) { Log.e("", "url : " + uri); // authorize() ?? ??? url scheme??? ?? callback??? ????. MobileOAuthLibrary.getInstance().handleUrlScheme(uri); } } MobileOAuthLibrary.OAuthListener oAuthListener = new MobileOAuthLibrary.OAuthListener() { @Override public void onAuthorizeSuccess() { logText.append("onAuthorizeSuccess"); } @Override public void onAuthorizeFail(OAuthError.OAuthErrorCodes errorCode, String errorMessage) { logText.append("onAuthorizeFail : " + errorMessage); if (errorCode.equals(OAuthError.OAuthErrorCodes.OAuthErrorInvalidAuthorizationRequest)) { // ??????? ?? ??? ??. } else if (errorCode.equals(OAuthError.OAuthErrorCodes.OAuthErrorUnauthorizedClient)) { // ???????? ???? Client ID ? ??? ?? } else if (errorCode.equals(OAuthError.OAuthErrorCodes.OAuthErrorAccessDenied)) { // ????? ???? ???????? "??"? ?? ?? } else if (errorCode.equals(OAuthError.OAuthErrorCodes.OAuthErrorUnsupportedResponseType)) { // ??????? ?? ??????????? ??? ?? } else if (errorCode.equals(OAuthError.OAuthErrorCodes.OAuthErrorInvalidScope)) { // ??? ?? ????? ?? ??. } } @Override public void onRequestResourceSuccess(String response) { LoadingIndicator.getInstance().stopLoadingIndicator(MainActivity.this); // ?? ????? ???? ????. logText.append("onRequestResourceSuccess : " + response); } @Override public void onRequestResourceFail(OAuthError.OAuthErrorCodes errorCode, String errorMessage) { LoadingIndicator.getInstance().stopLoadingIndicator(MainActivity.this); logText.append("onRequestResourceFail : " + errorMessage); if (errorCode.equals(OAuthError.OAuthErrorCodes.OAuthErrorInvalidToken)) { // access token ??? ??? ??????? ?? or 401 ??? // authorize() ? ?? ?? access token??? ?? ????. } else if (errorCode.equals(OAuthError.OAuthErrorCodes.OAuthErrorInvalidResourceRequest)) { // ??? ??? 400 ???? ???? ?? } else if (errorCode.equals(OAuthError.OAuthErrorCodes.OAuthErrorInsufficientScope)) { // ??? ??? 403 ???? ???? ?? } else if (errorCode.equals(OAuthError.OAuthErrorCodes.OAuthErrorServiceNotFound)) { // ??? ??? 404 ???? ???? ?? } else if (errorCode.equals(OAuthError.OAuthErrorCodes.OAuthErrorNetwork)) { // ?? ???????? ??????? ????? ? ?? ?? } else if (errorCode.equals(OAuthError.OAuthErrorCodes.OAuthErrorServer)) { // ?????? ???? ????? ?? // ?? ??????? ??? ?? ??????? api ????? ?????. } else if (errorCode.equals(OAuthError.OAuthErrorCodes.OAuthErrorUnknown)) { // ??? ??? ? ? ?? ?? ???? ???? ??. } } }; @Override protected void onDestroy() { super.onDestroy(); // ????? ????? ??? ?????? ??. MobileOAuthLibrary.getInstance().uninitialize(); } }