Java Code Examples for com.sina.weibo.sdk.auth.Oauth2AccessToken#getToken()

The following examples show how to use com.sina.weibo.sdk.auth.Oauth2AccessToken#getToken() . 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: AccessTokenKeeper.java    From Simpler with Apache License 2.0 6 votes vote down vote up
/**
 * 保存 Token 对象到数据库,并设置为当前用户。
 *
 * @param token Token 对象
 */
public static void writeAccessToken(Oauth2AccessToken token) {
    String uid = token.getUid();
    Account account = new Account(uid, token.getToken(), token.getExpiresTime(), token.getRefreshToken());
    // 设置当前的用户ID
    BaseConfig.sUid = uid;
    AccountUtil.updateOauth2AccessToken(token);
    SettingsUtil.insertSettingsSafely(uid);

    if (BaseConfig.sAccount == null) {
        // 设置当前帐户
        BaseConfig.sAccount = account;
    }
    // 设置当前应用设置
    BaseSettings.sSettings = SettingsUtil.readSettings(uid, false);
    // 保存当前用户ID
    PrefsUtils.putString(Constants.PREFS_CUR_UID, uid);
}
 
Example 2
Source File: UserServices.java    From Simpler with Apache License 2.0 5 votes vote down vote up
/**
 * 更新Oauth2AccessToken
 *
 * @param uid   用户Id
 * @param token Oauth2AccessToken
 */
public void updateOauth2AccessToken(String uid, Oauth2AccessToken token) {
    SQLiteDatabase db = this.dbHelper.getReadableDatabase();
    String sql = "UPDATE " + DBInfo.Table.USER_TB_NAME + " SET " + Account.ACCESS_TOKEN + "='"
            + token.getToken() + "', " + Account.EXPIRES_IN + "=" + token.getExpiresTime()
            + ", " + Account.REFRESH_TOKEN + "='" + token.getRefreshToken()
            + "' WHERE " + Account.UID + "='" + uid + "'";
    db.execSQL(sql);
    db.close();
}
 
Example 3
Source File: AccountUtil.java    From Simpler with Apache License 2.0 5 votes vote down vote up
/**
 * 更新Oauth2AccessToken
 *
 * @param token
 */
public static void updateOauth2AccessToken(Oauth2AccessToken token) {
    BaseConfig.sAccessToken = token;
    if (App.userServices.getAccountById(BaseConfig.sUid) == null) {
        // 同步到数据库
        Account account = new Account(BaseConfig.sUid, token.getToken(), token.getExpiresTime(), token.getRefreshToken());
        App.userServices.insertAccount(account);
    } else {
        // 同步到数据库
        App.userServices.updateOauth2AccessToken(BaseConfig.sUid, token);
    }
}
 
Example 4
Source File: SinaShareHandler.java    From BiliShare with Apache License 2.0 5 votes vote down vote up
private String getToken() {
    Oauth2AccessToken mAccessToken = AccessTokenKeeper.readAccessToken(getContext());
    String token = null;
    if (mAccessToken != null) {
        token = mAccessToken.getToken();
    }
    return token;
}
 
Example 5
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 6
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);
    }