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

The following examples show how to use com.sina.weibo.sdk.auth.WeiboAuthListener. 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: SsoHandler.java    From letv with Apache License 2.0 6 votes vote down vote up
private void authorize(int requestCode, WeiboAuthListener listener, AuthType authType) {
    this.mSSOAuthRequestCode = requestCode;
    this.mAuthListener = listener;
    boolean onlyClientSso = false;
    if (authType == AuthType.SsoOnly) {
        onlyClientSso = true;
    }
    if (authType == AuthType.WebOnly) {
        if (listener != null) {
            this.mWebAuthHandler.anthorize(listener);
        }
    } else if (!bindRemoteSSOService(this.mAuthActivity.getApplicationContext())) {
        if (!onlyClientSso) {
            this.mWebAuthHandler.anthorize(this.mAuthListener);
        } else if (this.mAuthListener != null) {
            this.mAuthListener.onWeiboException(new WeiboException(AUTH_FAILED_NOT_INSTALL_MSG));
        }
    }
}
 
Example #2
Source File: WeiboShareProxy.java    From ESSocialSDK with Apache License 2.0 5 votes vote down vote up
private static void shareTo(final Context context, final String appKey, final String title, final String desc,
                            final String imageUrl, final String shareUrl, final WeiboAuthListener listener) {

    shareTo(context, appKey, "http://www.sina.com", "email,direct_messages_read,direct_messages_write,"
            + "friendships_groups_read,friendships_groups_write,statuses_to_me_read,"
            + "follow_app_official_microblog," + "invitation_write", title, desc, imageUrl, shareUrl, listener);

}
 
Example #3
Source File: WeiboShareProxy.java    From ESSocialSDK with Apache License 2.0 5 votes vote down vote up
public static void shareTo(final Context context, final String appKey, final String redirectUrl, final String title, final String desc,
                           final String imageUrl, final String shareUrl, final WeiboAuthListener listener) {
    if (TextUtils.isEmpty(redirectUrl)) {
        shareTo(context, appKey, title, desc, imageUrl, shareUrl, listener);
    } else {
        shareTo(context, appKey, redirectUrl, "email,direct_messages_read,direct_messages_write,"
                + "friendships_groups_read,friendships_groups_write,statuses_to_me_read,"
                + "follow_app_official_microblog," + "invitation_write", title, desc, imageUrl, shareUrl, listener);
    }

}
 
Example #4
Source File: WeiboShareProxy.java    From ESSocialSDK with Apache License 2.0 5 votes vote down vote up
private static void shareTo(final Context context, final String appKey, final String redirectUrl, final String scop, final String title, final String desc,
                            final String imageUrl, final String shareUrl, final WeiboAuthListener listener) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            WeiboMultiMessage msg = new WeiboMultiMessage();
            TextObject text = new TextObject();
            text.text = desc;
            msg.textObject = text;
            WebpageObject web = new WebpageObject();
            web.description = desc;
            byte[] thumb = SocialUtils.getHtmlByteArray(imageUrl);
            if (null != thumb)
                web.thumbData = SocialUtils.compressBitmap(thumb, 32);
            else
                web.thumbData = SocialUtils.compressBitmap(SocialUtils.getDefaultShareImage(context), 32);
            web.actionUrl = shareUrl;
            web.identify = imageUrl;
            web.title = title;
            msg.mediaObject = web;

            SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
            request.transaction = String.valueOf(System.currentTimeMillis());
            request.multiMessage = msg;

            AuthInfo authInfo = new AuthInfo(context, appKey, redirectUrl, scop);
            Oauth2AccessToken accessToken = AccessTokenKeeper.readAccessToken(context);
            String token = "";
            if (accessToken != null) {
                token = accessToken.getToken();
            }
            getInstance(context, appKey).sendRequest((Activity) context, request, authInfo, token, listener);
        }
    }).start();

}
 
Example #5
Source File: SocialShareProxy.java    From ESSocialSDK with Apache License 2.0 5 votes vote down vote up
/**
     * 分享到微博
     *
     * @param context     context
     * @param appKey      app key
     * @param redirectUrl 回调地址
     * @param scene       场景
     */
    public static void shareToWeibo(final Context context, String appKey, String redirectUrl, final SocialShareScene scene) {
        if (DEBUG)
            Log.i(TAG, "SocialShareProxy#shareToWeibo");
        WeiboShareProxy.shareTo(context, appKey, redirectUrl, scene.getTitle(), scene.getDesc(),
                scene.getThumbnail(), scene.getUrl(), new WeiboAuthListener() {
                    @Override
                    public void onComplete(Bundle bundle) {
                        if (DEBUG)
                            Log.i(TAG, "SocialShareProxy#shareToWeibo onComplete");
                        Oauth2AccessToken token = Oauth2AccessToken.parseAccessToken(bundle);
                        if (token.isSessionValid())
                            AccessTokenKeeper.writeAccessToken(context, token);
//                        BusProvider.getInstance().post(new ShareBusEvent(ShareBusEvent.TYPE_SUCCESS, scene.getType(), scene.getId()));
                    }

                    @Override
                    public void onWeiboException(WeiboException e) {
                        if (DEBUG)
                            Log.i(TAG, "SocialShareProxy#shareToWeibo onWeiboException " + e.toString());
//                        BusProvider.getInstance().post(new ShareBusEvent(ShareBusEvent.TYPE_FAILURE, scene.getType(), e));
                    }

                    @Override
                    public void onCancel() {
                        if (DEBUG)
                            Log.i(TAG, "SocialShareProxy#shareToWeibo onCancel");
//                        BusProvider.getInstance().post(new ShareBusEvent(ShareBusEvent.TYPE_CANCEL, scene.getType()));
                    }
                });

    }
 
Example #6
Source File: WeiboSdkBrowser.java    From letv with Apache License 2.0 5 votes vote down vote up
public static void startAuth(Context context, String url, AuthInfo authInfo, WeiboAuthListener listener) {
    AuthRequestParam reqParam = new AuthRequestParam(context);
    reqParam.setLauncher(BrowserLauncher.AUTH);
    reqParam.setUrl(url);
    reqParam.setAuthInfo(authInfo);
    reqParam.setAuthListener(listener);
    Intent intent = new Intent(context, WeiboSdkBrowser.class);
    intent.putExtras(reqParam.createRequestParamBundle());
    context.startActivity(intent);
}
 
Example #7
Source File: WeiboLoginInstance.java    From ShareUtil with Apache License 2.0 5 votes vote down vote up
@Override
public void doLogin(Activity activity, final LoginListener listener,
        final boolean fetchUserInfo) {
    mSsoHandler.authorize(new WeiboAuthListener() {
        @Override
        public void onComplete(Bundle bundle) {
            Oauth2AccessToken accessToken = Oauth2AccessToken.parseAccessToken(bundle);
            WeiboToken weiboToken = WeiboToken.parse(accessToken);
            if (fetchUserInfo) {
                listener.beforeFetchUserInfo(weiboToken);
                fetchUserInfo(weiboToken);
            } else {
                listener.loginSuccess(new LoginResult(LoginPlatform.WEIBO, weiboToken));
            }
        }

        @Override
        public void onWeiboException(WeiboException e) {
            ShareLogger.i(INFO.WEIBO_AUTH_ERROR);
            listener.loginFailure(e);
        }

        @Override
        public void onCancel() {
            ShareLogger.i(INFO.AUTH_CANCEL);
            listener.loginCancel();
        }
    });
}
 
Example #8
Source File: SsoHandler.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public void authorize(int i, WeiboAuthListener weiboauthlistener, String s)
{
    mSSOAuthRequestCode = i;
    mAuthListener = weiboauthlistener;
    if (!bindRemoteSSOService(mAuthActivity.getApplicationContext(), s) && mWeibo != null)
    {
        mWeibo.anthorize(mAuthListener);
    }
}
 
Example #9
Source File: SsoHandler.java    From letv with Apache License 2.0 5 votes vote down vote up
public void registerOrLoginByMobile(String title, WeiboAuthListener listener) {
    this.mAuthListener = listener;
    Intent intentTemp = new Intent(this.mAuthActivity, MobileRegisterActivity.class);
    Bundle param = this.mAuthInfo.getAuthBundle();
    param.putString("register_title", title);
    intentTemp.putExtras(param);
    this.mAuthActivity.startActivityForResult(intentTemp, REQUEST_CODE_MOBILE_REGISTER);
}
 
Example #10
Source File: SharePopWindow.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
private void share2weibo() {
	setShareContent();
	// 1. 初始化微博的分享消息
       WeiboMultiMessage weiboMessage = new WeiboMultiMessage();
       weiboMessage.mediaObject = getWebpageObj();
       weiboMessage.textObject = getTextObj();    //这里可以设置文本
       if(mJoke.getType() != Joke.TYPE_QUSHI) {
       	weiboMessage.imageObject = getImageObj();
       }
      // 2. 初始化从第三方到微博的消息请求
       SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
       // 用transaction唯一标识一个请求
       request.transaction = String.valueOf(System.currentTimeMillis());
       request.multiMessage = weiboMessage;
       
       AuthInfo authInfo = new AuthInfo(context, com.sina.weibo.Constants.APP_KEY, com.sina.weibo.Constants.REDIRECT_URL, com.sina.weibo.Constants.SCOPE);
       Oauth2AccessToken accessToken = AccessTokenKeeper.readAccessToken(context);
       String token = "";
       if (accessToken != null) {
           token = accessToken.getToken();
       }
       mWeiboShareAPI.sendRequest((Activity)context, request, authInfo, token, new WeiboAuthListener() {
           @Override
           public void onWeiboException( WeiboException arg0 ) {
           	Log.e(TAG, "share sina weibo error", arg0);
           	ToastUtils.showMessage(context, "分享失败");
           }
           @Override
           public void onComplete( Bundle bundle ) {
               Oauth2AccessToken newToken = Oauth2AccessToken.parseAccessToken(bundle);
               AccessTokenKeeper.writeAccessToken(context, newToken);
               ImgToastUtils.showMessage(context, "分享成功", R.drawable.center_ok_tip);
           }
           @Override
           public void onCancel() {
           }
       });
}
 
Example #11
Source File: WeiboLoginInstance.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
@Override
public void doLogin(Activity activity, final LoginListener listener,
                    final boolean fetchUserInfo) {
    mSsoHandler.authorize(new WeiboAuthListener() {
        @Override
        public void onComplete(Bundle bundle) {
            Oauth2AccessToken accessToken = Oauth2AccessToken.parseAccessToken(bundle);
            WeiboToken weiboToken = WeiboToken.parse(accessToken);
            if (fetchUserInfo) {
                listener.beforeFetchUserInfo(weiboToken);
                fetchUserInfo(weiboToken);
            } else {
                listener.loginSuccess(new LoginResult(LoginPlatform.WEIBO, weiboToken));
            }
        }

        @Override
        public void onWeiboException(WeiboException e) {
            ShareLogger.i(INFO.WEIBO_AUTH_ERROR);
            listener.loginFailure(e);
        }

        @Override
        public void onCancel() {
            ShareLogger.i(INFO.AUTH_CANCEL);
            listener.loginCancel();
        }
    });
}
 
Example #12
Source File: AuthRequestParam.java    From letv with Apache License 2.0 4 votes vote down vote up
public void setAuthListener(WeiboAuthListener mAuthListener) {
    this.mAuthListener = mAuthListener;
}
 
Example #13
Source File: AuthRequestParam.java    From letv with Apache License 2.0 4 votes vote down vote up
public WeiboAuthListener getAuthListener() {
    return this.mAuthListener;
}
 
Example #14
Source File: SinaShareImpl.java    From ChinaShare with MIT License 4 votes vote down vote up
/**
 * 获取新浪微博授权
 */
private void authorizeSinaWeibo(WeiboAuthListener listener) {
    // mSsoHandler = new SsoHandler(mActivity, mAuthInfo);
    // SSO 授权, ALL IN ONE   如果手机安装了微博客户端则使用客户端授权,没有则进行网页授权
    mSsoHandler.authorize(listener);
}
 
Example #15
Source File: SinaWBHandler.java    From SocialSDKAndroid with Apache License 2.0 4 votes vote down vote up
@Override
    public void share(Activity activity, IShareMedia shareMedia, ShareListener shareListener) {
        this.mActivity = activity;
        this.mShareListener = shareListener;

        this.mSsoHandler = new SsoHandler(mActivity, mAuthInfo);

        WeiboMultiMessage weiboMessage = new WeiboMultiMessage();

        if(shareMedia instanceof ShareTextImageMedia) {       //文字图片分享
            ShareTextImageMedia shareTextImageMedia = (ShareTextImageMedia) shareMedia;

            if(shareTextImageMedia.getText().length() > 0) {
                TextObject textObject = new TextObject();
                textObject.text = shareTextImageMedia.getText();
                weiboMessage.textObject = textObject;
            }

            if(shareTextImageMedia.getImage() != null) {
                ImageObject imageObject = new ImageObject();
                imageObject.setImageObject(shareTextImageMedia.getImage());
                weiboMessage.imageObject = imageObject;
            }
        } else {
            if(this.mShareListener != null) {
                this.mShareListener.onError(this.mConfig.getName(), "weibo is not support this shareMedia");
            }
            return ;
        }

        SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
        request.transaction = String.valueOf(System.currentTimeMillis());
        request.multiMessage = weiboMessage;

        Oauth2AccessToken accessToken = AccessTokenKeeper.readAccessToken(mContext.getApplicationContext());
        String token = "";
        if (accessToken != null) {
            token = accessToken.getToken();
        }
        mWeiboShareAPI.sendRequest(mActivity, request, mAuthInfo, token, new WeiboAuthListener() {

            @Override
            public void onWeiboException( WeiboException arg0 ) {
            }

            @Override
            public void onComplete( Bundle bundle ) {
                // TODO Auto-generated method stub
                Oauth2AccessToken newToken = Oauth2AccessToken.parseAccessToken(bundle);
                AccessTokenKeeper.writeAccessToken(mContext.getApplicationContext(), newToken);
            }

            @Override
            public void onCancel() {
            }
        });

//        mWeiboShareAPI.sendRequest(mActivity, request);
    }
 
Example #16
Source File: SsoHandler.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public void authorize(WeiboAuthListener weiboauthlistener)
{
    authorize(32973, weiboauthlistener, null);
}
 
Example #17
Source File: SsoHandler.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public void authorize(WeiboAuthListener weiboauthlistener, String s)
{
    authorize(32973, weiboauthlistener, s);
}
 
Example #18
Source File: WeiboSSOProxy.java    From ESSocialSDK with Apache License 2.0 4 votes vote down vote up
public static void login(Context context, SocialInfo info, WeiboAuthListener listener) {
    if (!SocialSSOProxy.isTokenValid(context)) {
        getSsoHandler(context, info).authorize(listener);
    }
}
 
Example #19
Source File: WeiboSdkBrowser.java    From letv with Apache License 2.0 4 votes vote down vote up
public static void startShared(Context context, String url, AuthInfo authInfo, WeiboAuthListener listener) {
}
 
Example #20
Source File: SsoHandler.java    From letv with Apache License 2.0 4 votes vote down vote up
public void authorize(WeiboAuthListener listener) {
    authorize(REQUEST_CODE_SSO_AUTH, listener, AuthType.ALL);
    WbAppActivator.getInstance(this.mAuthActivity, this.mAuthInfo.getAppKey()).activateApp();
}
 
Example #21
Source File: SsoHandler.java    From letv with Apache License 2.0 4 votes vote down vote up
public void authorizeClientSso(WeiboAuthListener listener) {
    authorize(REQUEST_CODE_SSO_AUTH, listener, AuthType.SsoOnly);
    WbAppActivator.getInstance(this.mAuthActivity, this.mAuthInfo.getAppKey()).activateApp();
}
 
Example #22
Source File: SsoHandler.java    From letv with Apache License 2.0 4 votes vote down vote up
public void authorizeWeb(WeiboAuthListener listener) {
    authorize(REQUEST_CODE_SSO_AUTH, listener, AuthType.WebOnly);
    WbAppActivator.getInstance(this.mAuthActivity, this.mAuthInfo.getAppKey()).activateApp();
}
 
Example #23
Source File: WeiboCallbackManager.java    From letv with Apache License 2.0 4 votes vote down vote up
public synchronized void setWeiboAuthListener(String callbackId, WeiboAuthListener authListener) {
    if (!(TextUtils.isEmpty(callbackId) || authListener == null)) {
        this.mWeiboAuthListenerMap.put(callbackId, authListener);
    }
}
 
Example #24
Source File: WidgetRequestParam.java    From letv with Apache License 2.0 4 votes vote down vote up
public WeiboAuthListener getAuthListener() {
    return this.mAuthListener;
}
 
Example #25
Source File: WidgetRequestParam.java    From letv with Apache License 2.0 4 votes vote down vote up
public void setAuthListener(WeiboAuthListener mAuthListener) {
    this.mAuthListener = mAuthListener;
}
 
Example #26
Source File: ShareRequestParam.java    From letv with Apache License 2.0 4 votes vote down vote up
public WeiboAuthListener getAuthListener() {
    return this.mAuthListener;
}
 
Example #27
Source File: ShareRequestParam.java    From letv with Apache License 2.0 4 votes vote down vote up
public void setAuthListener(WeiboAuthListener mAuthListener) {
    this.mAuthListener = mAuthListener;
}
 
Example #28
Source File: LoginButton.java    From Simpler with Apache License 2.0 2 votes vote down vote up
/**
    * 设置微博授权所需信息。
    * 
    * @param appKey       第三方应用的 APP_KEY
    * @param redirectUrl  第三方应用的回调页
    * @param scope        第三方应用申请的权限
    * @param authListener 微博授权认证回调接口
    */
   public void setWeiboAuthInfo(String appKey, String redirectUrl, String scope, WeiboAuthListener authListener) {
	mAuthInfo = new AuthInfo(mContext, appKey, redirectUrl, scope);
	mAuthListener = authListener;
}
 
Example #29
Source File: LoginButton.java    From Simpler with Apache License 2.0 2 votes vote down vote up
/**
    * 设置微博授权所需信息以及回调函数。
    * 
    * @param authInfo     用于保存授权认证所需要的信息
    * @param authListener 微博授权认证回调接口
    */
   public void setWeiboAuthInfo(AuthInfo authInfo, WeiboAuthListener authListener) {
	mAuthInfo = authInfo;
	mAuthListener = authListener;
}
 
Example #30
Source File: LoginoutButton.java    From Simpler with Apache License 2.0 2 votes vote down vote up
/**
    * 设置微博授权所需信息。
    * 
    * @param appKey       第三方应用的 APP_KEY
    * @param redirectUrl  第三方应用的回调页
    * @param scope        第三方应用申请的权限
    * @param authListener 微博授权认证回调接口
    */
   public void setWeiboAuthInfo(String appKey, String redirectUrl, String scope, WeiboAuthListener authListener) {
	mAuthInfo = new AuthInfo(mContext, appKey, redirectUrl, scope);
	mAuthListener = authListener;
}