Java Code Examples for com.sina.weibo.sdk.auth.Oauth2AccessToken#parseAccessToken()
The following examples show how to use
com.sina.weibo.sdk.auth.Oauth2AccessToken#parseAccessToken() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseDialog.java From AssistantBySDK with Apache License 2.0 | 6 votes |
@Override public void onComplete(Bundle values) { Log.i(TAG, "AuthListener.onComplete"); Oauth2AccessToken accessToken = Oauth2AccessToken.parseAccessToken(values); if (accessToken != null && accessToken.isSessionValid()) { //UsersAPI userAPI=new UsersAPI(accessToken); //userAPI.show(Long.parseLong(accessToken.getUid()), userListener); String date = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format( new java.util.Date(accessToken.getExpiresTime())); System.out.println("uid=" + accessToken.getUid()); System.out.println("access_token=" + accessToken.getToken()); System.out.println("expiresTime=" + date); AccessTokenKeeper.writeAccessToken(mContext, accessToken); shareToWeibo(); } }
Example 2
Source File: SinaShareImpl.java From ChinaShare with MIT License | 6 votes |
@Override public void onComplete(Bundle values) { // 从 Bundle 中解析 Token mAccessToken = Oauth2AccessToken.parseAccessToken(values); if (mAccessToken.isSessionValid()) { // 保存 Token 到 SharedPreferences AccessTokenKeeper.writeAccessToken(mActivity, mAccessToken); sendWeiBoMessage(shareInfo); Toast.makeText(mActivity, R.string.suc_auth_sina, Toast.LENGTH_SHORT).show(); } else { // 以下几种情况,您会收到 Code: // 1. 当您未在平台上注册的应用程序的包名与签名时; // 2. 当您注册的应用程序包名与签名不正确时; // 3. 当您在平台上注册的包名和签名与您当前测试的应用的包名和签名不匹配时。 String code = values.getString("code"); String message = "授权失败"; if (!TextUtils.isEmpty(code)) { message = message + "\nObtained the code: " + code; } Toast.makeText(mActivity, message, Toast.LENGTH_LONG).show(); } }
Example 3
Source File: BaseHandler.java From LoginSharePay with Apache License 2.0 | 5 votes |
public void authorizeCallBack(int requestCode, int resultCode, Intent data) { if ('胍' == requestCode) { if (resultCode == -1) { if (!SecurityHelper.checkResponseAppLegal(this.mAuthFragment.getContext(), WeiboAppManager.getInstance(this.mAuthFragment.getContext()).getWbAppInfo(), data)) { this.authListener.onFailure(new WbConnectErrorMessage("your install weibo app is counterfeit", "8001")); return; } String error = Utility.safeString(data.getStringExtra("error")); String error_type = Utility.safeString(data.getStringExtra("error_type")); String error_description = Utility.safeString(data.getStringExtra("error_description")); LogUtil.d("WBAgent", "error: " + error + ", error_type: " + error_type + ", error_description: " + error_description); if (TextUtils.isEmpty(error) && TextUtils.isEmpty(error_type) && TextUtils.isEmpty(error_description)) { Bundle bundle = data.getExtras(); Oauth2AccessToken accessToken = Oauth2AccessToken.parseAccessToken(bundle); if (accessToken != null && accessToken.isSessionValid()) { LogUtil.d("WBAgent", "Login Success! " + accessToken.toString()); AccessTokenKeeper.writeAccessToken(this.mAuthFragment.getContext(), accessToken); this.authListener.onSuccess(accessToken); } } else if (!"access_denied".equals(error) && !"OAuthAccessDeniedException".equals(error)) { LogUtil.d("WBAgent", "Login failed: " + error); this.authListener.onFailure(new WbConnectErrorMessage(error_type, error_description)); } else { LogUtil.d("WBAgent", "Login canceled by user."); this.authListener.cancel(); } } else if (resultCode == 0) { if (data != null) { this.authListener.cancel(); } else { this.authListener.cancel(); } } } }
Example 4
Source File: WBLoginActivity.java From Simpler with Apache License 2.0 | 5 votes |
@Override public void onComplete(Bundle values) { // 从 Bundle 中解析 Token mAccessToken = Oauth2AccessToken.parseAccessToken(values); //从这里获取用户输入的 电话号码信息 String phoneNum = mAccessToken.getPhoneNum(); if (mAccessToken.isSessionValid()) { // Log.d("Auth", sAccessToken.toString()); // 保存 Token AccessTokenKeeper.writeAccessToken(mAccessToken); AppToast.showToast(R.string.weibosdk_demo_toast_auth_success, Toast.LENGTH_SHORT); BaseConfig.sTokenExpired = false; if (BaseConfig.sAddAccountMode) { // 添加帐号模式,结束之前所有Activity App.getInstance().finishAllActivities(); } startActivity(MainActivity.newIntent(WBLoginActivity.this)); } else { // 以下几种情况,您会收到 Code: // 1. 当您未在平台上注册的应用程序的包名与签名时; // 2. 当您注册的应用程序包名与签名不正确时; // 3. 当您在平台上注册的包名和签名与您当前测试的应用的包名和签名不匹配时。 String code = values.getString("code"); String message = getString(R.string.weibosdk_demo_toast_auth_failed); if (!TextUtils.isEmpty(code)) { message = message + "\nObtained the code: " + code; } AppToast.showToast(message, Toast.LENGTH_LONG); } finish(); }
Example 5
Source File: AuthPresenter.java From the-tech-frontier-app with MIT License | 5 votes |
@Override public void onComplete(Bundle values) { mAccessToken = Oauth2AccessToken.parseAccessToken(values); if (mAccessToken.isSessionValid()) { final String uid = mAccessToken.getUid(); final String token = mAccessToken.getToken(); Log.i("RESULT", mAccessToken.toString()); mUserAPI.fetchUserInfo(uid, token, new DataListener<UserInfo>() { @Override public void onComplete(UserInfo result) { result.token = token; result.uid = uid; LoginSession.getLoginSession().saveUserInfo(result); if (mDataListener != null) { mDataListener.onComplete(result); } } }); } else { // 以下几种情况,您会收到 Code: // 1. 当您未在平台上注册的应用程序的包名与签名时; // 2. 当您注册的应用程序包名与签名不正确时; // 3. 当您在平台上注册的包名和签名与您当前测试的应用的包名和签名不匹配时。 // String code = values.getString("code"); } }
Example 6
Source File: SsoHandler.java From letv with Apache License 2.0 | 4 votes |
public void authorizeCallBack(int requestCode, int resultCode, Intent data) { LogUtil.d(TAG, "requestCode: " + requestCode + ", resultCode: " + resultCode + ", data: " + data); String error; Bundle bundle; Oauth2AccessToken accessToken; if (requestCode == this.mSSOAuthRequestCode) { if (resultCode == -1) { if (SecurityHelper.checkResponseAppLegal(this.mAuthActivity, this.mWeiboInfo, data)) { error = data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_BUNDLE); if (error == null) { error = data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_TYPE); } if (error == null) { bundle = data.getExtras(); accessToken = Oauth2AccessToken.parseAccessToken(bundle); if (accessToken == null || !accessToken.isSessionValid()) { LogUtil.d(TAG, "Failed to receive access token by SSO"); this.mWebAuthHandler.anthorize(this.mAuthListener); return; } LogUtil.d(TAG, "Login Success! " + accessToken.toString()); this.mAuthListener.onComplete(bundle); } else if (error.equals("access_denied") || error.equals("OAuthAccessDeniedException")) { LogUtil.d(TAG, "Login canceled by user."); this.mAuthListener.onCancel(); } else { String description = data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_DESCRIPTION); if (description != null) { error = new StringBuilder(String.valueOf(error)).append(NetworkUtils.DELIMITER_COLON).append(description).toString(); } LogUtil.d(TAG, "Login failed: " + error); this.mAuthListener.onWeiboException(new WeiboDialogException(error, resultCode, description)); } } } else if (resultCode != 0) { } else { if (data != null) { LogUtil.d(TAG, "Login failed: " + data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_BUNDLE)); this.mAuthListener.onWeiboException(new WeiboDialogException(data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_BUNDLE), data.getIntExtra(NativeProtocol.BRIDGE_ARG_ERROR_CODE, -1), data.getStringExtra("failing_url"))); return; } LogUtil.d(TAG, "Login canceled by user."); this.mAuthListener.onCancel(); } } else if (requestCode != REQUEST_CODE_MOBILE_REGISTER) { } else { if (resultCode == -1) { bundle = data.getExtras(); accessToken = Oauth2AccessToken.parseAccessToken(bundle); if (accessToken != null && accessToken.isSessionValid()) { LogUtil.d(TAG, "Login Success! " + accessToken.toString()); this.mAuthListener.onComplete(bundle); } } else if (resultCode != 0) { } else { if (data != null) { LogUtil.d(TAG, "Login failed: " + data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_BUNDLE)); error = data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_BUNDLE); if (error == null) { error = data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_TYPE); } if (error != null) { this.mAuthListener.onWeiboException(new WeiboDialogException(data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_BUNDLE), data.getIntExtra(NativeProtocol.BRIDGE_ARG_ERROR_CODE, -1), data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_DESCRIPTION))); return; } return; } LogUtil.d(TAG, "Login canceled by user."); this.mAuthListener.onCancel(); } } }