com.sina.weibo.sdk.WbSdk Java Examples

The following examples show how to use com.sina.weibo.sdk.WbSdk. 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: WBHelper.java    From SocialHelper with Apache License 2.0 6 votes vote down vote up
@Override
public void share(SocialShareCallback callback, ShareEntity shareInfo) {
    this.shareCallback = callback;
    if (baseVerify(callback)) {
        return;
    }
    if (!WbSdk.isWbInstall(activity)) {
        if (callback != null) {
            callback.socialError(activity.getString(R.string.social_wb_uninstall));
        }
        return;
    }
    initShareLister(shareInfo);
    shareHandler = new WbShareHandler(activity);
    shareHandler.registerApp();

    WeiboMultiMessage weiboMessage = getShareMessage(shareInfo.getParams());
    if (weiboMessage == null) {
        return;
    }
    shareHandler.shareMessage(weiboMessage, false);
}
 
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: WeiboShareManager.java    From sharesdk with Apache License 2.0 5 votes vote down vote up
WeiboShareManager(Context context) {
    Application app = (Application) context.getApplicationContext();
    app.registerActivityLifecycleCallbacks(this);
    mContext = context;
    mSinaAppKey = ShareSDK.getInstance().getWeiboAppId();
    mSinaRedirectUrl = ShareSDK.getInstance().getSinaRedirectUrl();
    mSinaScope = ShareSDK.getInstance().getWeiboScope();
    if (!TextUtils.isEmpty(mSinaAppKey)) {
        // 创建微博 SDK 接口实例
        AuthInfo mAuthInfo = new AuthInfo(context, mSinaAppKey, mSinaRedirectUrl, mSinaScope);
        WbSdk.install(context, mAuthInfo);
    }
}
 
Example #4
Source File: WbPlatform.java    From SocialSdkLibrary with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isInstall(Context context) {
    if (mTarget == Target.LOGIN_WB) {
        // 支持网页授权,所以不需要安装 app
        return true;
    }
    return WbSdk.isWbInstall(context);
}
 
Example #5
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 #6
Source File: WBAuth.java    From sdk3rd with Apache License 2.0 5 votes vote down vote up
WBAuth(Activity activity, Platform platform) {
    WbSdk.install(activity, new AuthInfo(activity, platform.getAppId(), platform.extra("redirectUrl"), "all"));
    mActivity = activity;
    mPlatform = platform;
    mApi = new SsoHandler(mActivity);

}
 
Example #7
Source File: WBShare.java    From sdk3rd with Apache License 2.0 5 votes vote down vote up
WBShare(Activity activity, Platform platform) {
    WbSdk.install(activity, new AuthInfo(activity, platform.getAppId(), platform.extra("redirectUrl"), "all"));
    mActivity = activity;
    mPlatform = platform;
    mApi = new WbShareHandler(mActivity);
    mApi.registerApp();
    services.put(this, true);
}
 
Example #8
Source File: BaseLoginShare.java    From LoginSharePay with Apache License 2.0 5 votes vote down vote up
@Override
public void launchWeiboLogin() {

    WbSdk.install(proxyFragment.getContext(), new AuthInfo(proxyFragment.getContext(), weiboValue, weiboRedirectUrl, weiboScope));

    if (ssoHandler == null) {
        ssoHandler = new SsoHandler(proxyFragment);
    }
}
 
Example #9
Source File: WBHelper.java    From SocialHelper with Apache License 2.0 5 votes vote down vote up
WBHelper(Activity activity, String appId, String redirectUrl) {
    this.activity = activity;
    this.appId = appId;
    this.redirectUrl = redirectUrl;
    if (TextUtils.isEmpty(appId) || TextUtils.isEmpty(redirectUrl)) {
        Log.w("WBHelper", "WeBo's appId or redirectUrl is empty!");
        return;
    }
    WbSdk.install(activity.getApplicationContext(), new AuthInfo(activity.getApplicationContext(), appId, redirectUrl, SCOPE));
}
 
Example #10
Source File: BaseHandler.java    From LoginSharePay with Apache License 2.0 5 votes vote down vote up
protected void startClientAuth(int requestCode) {
    try {
        WbAppInfo wbAppInfo = WeiboAppManager.getInstance(this.mAuthFragment.getContext()).getWbAppInfo();
        Intent intent = new Intent();
        intent.setClassName(wbAppInfo.getPackageName(), wbAppInfo.getAuthActivityName());
        intent.putExtras(WbSdk.getAuthInfo().getAuthBundle());
        intent.putExtra("_weibo_command_type", 3);
        intent.putExtra("_weibo_transaction", String.valueOf(System.currentTimeMillis()));
        intent.putExtra("aid", Utility.getAid(this.mAuthFragment.getContext(), WbSdk.getAuthInfo().getAppKey()));
        if (!SecurityHelper.validateAppSignatureForIntent(this.mAuthFragment.getContext(), intent)) {
            return;
        }

        this.fillExtraIntent(intent, requestCode);

        try {
            this.mAuthFragment.startActivityForResult(intent, this.ssoRequestCode);
        } catch (Exception var5) {
            if (this.authListener != null) {
                this.authListener.onFailure(new WbConnectErrorMessage());
            }

            this.couldNotStartWbSsoActivity();
        }
    } catch (Exception var6) {
        ;
    }

}
 
Example #11
Source File: WbShareHandler.java    From LoginSharePay with Apache License 2.0 5 votes vote down vote up
public void shareMessage(WeiboMultiMessage message, boolean clientOnly) {
    if(!this.hasRegister) {
        throw new RuntimeException("please call WbShareHandler.registerApp(),before use share function");
    } else if(WbSdk.isWbInstall(this.context) || !clientOnly) {
        if(!clientOnly && !WbSdk.isWbInstall(this.context)) {
            this.startWebShare(message);
        } else {
            this.startClientShare(message);
        }

    }
}
 
Example #12
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);
    }

}
 
Example #13
Source File: Share.java    From UPMiss with GNU General Public License v3.0 4 votes vote down vote up
public static void init(Context context) {
    // 微博初始化
    AuthInfo mAuthInfo = new AuthInfo(context, Constants.WB_APP_ID, Constants.WB_REDIRECT_URL, Constants.WB_SCOPE);
    WbSdk.install(context, mAuthInfo);
}
 
Example #14
Source File: WbPlatform.java    From SocialSdkLibrary with Apache License 2.0 4 votes vote down vote up
private WbPlatform(Context context, String appId, String appName, int target, String redirectUrl, String scope) {
    super(context, appId, appName, target);
    AuthInfo authInfo = new AuthInfo(context, appId, redirectUrl, scope);
    WbSdk.install(context, authInfo);
}
 
Example #15
Source File: WbShareHandler.java    From LoginSharePay with Apache License 2.0 4 votes vote down vote up
public boolean registerApp() {
    this.sendBroadcast(this.context, "com.sina.weibo.sdk.Intent.ACTION_WEIBO_REGISTER", WbSdk.getAuthInfo().getAppKey(), (String)null, (Bundle)null);
    this.hasRegister = true;
    return true;
}
 
Example #16
Source File: WeiboShareInstance.java    From ShareLoginPayUtil with Apache License 2.0 4 votes vote down vote up
public WeiboShareInstance(Context context, String appId, String redirectUrl, String scope) {
    AuthInfo authInfo = new AuthInfo(context, appId, redirectUrl, scope);
    WbSdk.install(context, authInfo);
    shareHandler = new WbShareHandler((Activity) context);
    shareHandler.registerApp();
}
 
Example #17
Source File: BaseHandler.java    From LoginSharePay with Apache License 2.0 4 votes vote down vote up
public BaseHandler(Fragment activity) {
    this.mAuthFragment = activity;
    AidTask.getInstance(this.mAuthFragment.getContext()).aidTaskInit(WbSdk.getAuthInfo().getAppKey());
}
 
Example #18
Source File: BaseLoginShare.java    From LoginSharePay with Apache License 2.0 4 votes vote down vote up
@Override
public void launchWeiboShare(WeiboMessageBody weiboMessageBody) {
    WbSdk.install(proxyFragment.getContext(), new AuthInfo(proxyFragment.getContext(), weiboValue, weiboRedirectUrl, weiboScope));
    shareHandler = new WbShareHandler(proxyFragment.getContext());
    shareHandler.registerApp();
}
 
Example #19
Source File: WBLoginInstance.java    From SimpleProject with MIT License 4 votes vote down vote up
public WBLoginInstance(Activity activity, String appKey, String redirectUrl, String scope, AuthListener listener) {
	this.listener = listener;
	AuthInfo authInfo = new AuthInfo(activity, appKey, redirectUrl, scope);
	WbSdk.install(activity, authInfo);
	ssoHandler = new SsoHandler(activity);
}
 
Example #20
Source File: WeiboLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isInstall(Context context) {
    return WbSdk.isWbInstall(context);
}
 
Example #21
Source File: WeiboLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 4 votes vote down vote up
public WeiboLoginInstance(Activity activity, LoginListener listener, String appId, String redirectUrl, String scope, boolean fetchUserInfo) {
    super(activity, listener, fetchUserInfo);
    AuthInfo authInfo = new AuthInfo(activity, appId, redirectUrl, scope);
    WbSdk.install(activity, authInfo);
    mSsoHandler = new SsoHandler(activity);
}
 
Example #22
Source File: WeiboShareInstance.java    From ShareLoginPayUtil with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isInstall(Context context) {
    return WbSdk.isWbInstall(context);
}
 
Example #23
Source File: BaseHandler.java    From LoginSharePay with Apache License 2.0 2 votes vote down vote up
/**
* author  : Hacknife
* e-mail  : [email protected]
* github  : http://github.com/hacknife
* project : LoginShare
*/
   @Deprecated
   public boolean isWbAppInstalled() {
       return WbSdk.isWbInstall(this.mAuthFragment.getContext());
   }
 
Example #24
Source File: WbShareHandler.java    From LoginSharePay with Apache License 2.0 2 votes vote down vote up
/**
* author  : Hacknife
* e-mail  : [email protected]
* github  : http://github.com/hacknife
* project : LoginShare
*/
   @Deprecated
   public boolean isWbAppInstalled() {
       return WbSdk.isWbInstall(this.context);
   }