com.sina.weibo.sdk.auth.AccessTokenKeeper Java Examples

The following examples show how to use com.sina.weibo.sdk.auth.AccessTokenKeeper. 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: WeiboLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 6 votes vote down vote up
@Override
public void onSuccess(final Oauth2AccessToken token) {

    if (token == null) {
        listener.loginFailure(new Exception( ShareLogger.INFO.WEIBO_AUTH_ERROR), ShareLogger.INFO.ERR_GET_TOKEN_CODE);
        LoginUtil.recycle();
        return;
    }

    WeiboToken weiboToken = new WeiboToken(token);
    AccessTokenKeeper.writeAccessToken(mActivity, token);
    if (fetchUserInfo) {
        mLoginListener.beforeFetchUserInfo(weiboToken);
        fetchUserInfo(weiboToken);
    } else {
        mLoginListener.loginSuccess(new LoginResultData(LoginPlatform.WEIBO, weiboToken));
        LoginUtil.recycle();
    }
}
 
Example #2
Source File: WbShareHandler.java    From LoginSharePay with Apache License 2.0 6 votes vote down vote up
private void startWebShare(WeiboMultiMessage message) {
    Intent webIntent = new Intent(this.context, WbShareTransActivity.class);
    String appPackage = this.context.getPackageName();
    ShareWebViewRequestParam webParam = new ShareWebViewRequestParam(WbSdk.getAuthInfo(), WebRequestType.SHARE, "", 1, "微博分享", (String)null, this.context);
    webParam.setContext(this.context);
    webParam.setHashKey("");
    webParam.setPackageName(appPackage);
    Oauth2AccessToken token = AccessTokenKeeper.readAccessToken(this.context);
    if(token != null && !TextUtils.isEmpty(token.getToken())) {
        webParam.setToken(token.getToken());
    }

    webParam.setMultiMessage(message);
    Bundle bundle = new Bundle();
    webParam.fillBundle(bundle);
    webIntent.putExtras(bundle);
    webIntent.putExtra("startFlag", 0);
    webIntent.putExtra("startActivity", this.context.getClass().getName());
    webIntent.putExtra("startAction", "com.sina.weibo.sdk.action.ACTION_WEIBO_ACTIVITY");
    webIntent.putExtra("gotoActivity", "com.sina.weibo.sdk.web.WeiboSdkWebActivity");
    this.context.startActivity(webIntent);
}
 
Example #3
Source File: WeiboBaseShareInstance.java    From SimpleProject with MIT License 5 votes vote down vote up
public WeiboBaseShareInstance(Activity activity, ShareListener listener) {
	this.activity = activity;
	this.listener = listener;
	ImageLoaderManager.getInstance().init(activity.getApplicationContext(), new FrescoInstance());
	AuthInfo authInfo = new AuthInfo(activity, ShareConstants.APP_WEIBO_KEY, ShareConstants.REDIRECT_URL,
			ShareConstants.SCOPE);
		WbSdk.install(activity, authInfo);

	shareHandler = new WbShareHandler(activity);
	shareHandler.registerApp();
	accessToken = AccessTokenKeeper.readAccessToken(activity);
}
 
Example #4
Source File: WeiboBaseShareInstance.java    From SimpleProject with MIT License 5 votes vote down vote up
@Override
public void onSuccess(Oauth2AccessToken oauth2AccessToken) {
	accessToken = oauth2AccessToken;
	LogUtil.i("微博授权完成" + accessToken);
	if (accessToken.isSessionValid()) {
		AccessTokenKeeper.writeAccessToken(activity.getApplicationContext(), accessToken);
		onShare(null, desc, url, iconUrl);
	} else {
		LogUtil.i("微博开发账号签名错误");
		activity.finish();
	}
}
 
Example #5
Source File: BaseHandler.java    From LoginSharePay with Apache License 2.0 5 votes vote down vote up
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 #6
Source File: WBHelper.java    From SocialHelper with Apache License 2.0 5 votes vote down vote up
private void initLoginListener() {
    wbAuthCallback = new WbAuthListener() {
        @Override
        public void onSuccess(Oauth2AccessToken oauth2AccessToken) {
            if (oauth2AccessToken.isSessionValid()) {
                loginResult = oauth2AccessToken;
                AccessTokenKeeper.writeAccessToken(activity, oauth2AccessToken);
                getUserInfo(oauth2AccessToken);
            } else {
                handler.sendEmptyMessage(GET_INFO_ERROR);
            }
        }

        @Override
        public void cancel() {
            if (loginCallback != null && activity != null) {
                loginCallback.socialError(activity.getString(R.string.social_cancel));
            }
        }

        @Override
        public void onFailure(WbConnectErrorMessage error) {
            if (loginCallback != null) {
                loginCallback.socialError(error.getErrorMessage());
            }
        }
    };
}
 
Example #7
Source File: WeiboAuthManager.java    From sharesdk with Apache License 2.0 5 votes vote down vote up
@Override
public void login(org.henjue.library.share.AuthListener authListener) {
    mAuthListener = authListener;
    AccessTokenKeeper.clear(mContext);
    mAuthInfo = new com.sina.weibo.sdk.auth.AuthInfo(mContext, mSinaAppKey, ShareSDK.getInstance().getSinaRedirectUrl(), SCOPE);
    mSsoHandler = new SsoHandler((Activity) mContext);
    mSsoHandler.authorize(new AuthListener());

}
 
Example #8
Source File: WeiboAuthManager.java    From sharesdk with Apache License 2.0 5 votes vote down vote up
@Override
public void onSuccess(Oauth2AccessToken accessToken) {
    if (accessToken != null && accessToken.isSessionValid()) {
        AccessTokenKeeper.writeAccessToken(mContext, accessToken);
        userAPI = new UsersAPI(mContext, mSinaAppKey, accessToken);
        userAPI.show(this);
    }
}
 
Example #9
Source File: BaseHandler.java    From LoginSharePay with Apache License 2.0 4 votes vote down vote up
protected void startWebAuth() {
    AuthInfo authInfo = WbSdk.getAuthInfo();
    WeiboParameters requestParams = new WeiboParameters(authInfo.getAppKey());
    requestParams.put("client_id", authInfo.getAppKey());
    requestParams.put("redirect_uri", authInfo.getRedirectUrl());
    requestParams.put("scope", authInfo.getScope());
    requestParams.put("response_type", "code");
    requestParams.put("version", "0041005000");
    requestParams.put("luicode", "10000360");
    Oauth2AccessToken token = AccessTokenKeeper.readAccessToken(this.mAuthFragment.getContext());
    if (token != null && !TextUtils.isEmpty(token.getToken())) {
        requestParams.put("trans_token", token.getToken());
        requestParams.put("trans_access_token", token.getToken());
    }

    requestParams.put("lfid", "OP_" + authInfo.getAppKey());
    String aid = Utility.getAid(this.mAuthFragment.getContext(), authInfo.getAppKey());
    if (!TextUtils.isEmpty(aid)) {
        requestParams.put("aid", aid);
    }

    requestParams.put("packagename", authInfo.getPackageName());
    requestParams.put("key_hash", authInfo.getKeyHash());
    String url = "https://open.weibo.cn/oauth2/authorize?" + requestParams.encodeUrl();
    if (!NetworkHelper.hasInternetPermission(this.mAuthFragment.getContext())) {
        UIUtils.showAlert(this.mAuthFragment.getContext(), "Error", "Application requires permission to access the Internet");
    } else {
        String mAuthListenerKey = null;
        if (this.authListener != null) {
            WeiboCallbackManager manager = WeiboCallbackManager.getInstance();
            mAuthListenerKey = manager.genCallbackKey();
            manager.setWeiboAuthListener(mAuthListenerKey, this.authListener);
        }

        AuthWebViewRequestParam param = new AuthWebViewRequestParam(authInfo, WebRequestType.AUTH, mAuthListenerKey, "微博登录", url, this.mAuthFragment.getContext());
        Intent intent = new Intent(this.mAuthFragment.getContext(), WeiboSdkWebActivity.class);
        Bundle bundle = new Bundle();
        param.fillBundle(bundle);
        intent.putExtras(bundle);
        this.mAuthFragment.startActivity(intent);
    }

}