Esempio n. 1
0
 /** 接收腾讯微博授权的返回数据 */
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   // TODO Auto-generated method stub
   if (requestCode == REQUEST_CODE) { // 对应之前设置的的myRequsetCode
     if (resultCode == OAuthV2AuthorizeWebView.RESULT_CODE) {
       // 取得返回腾讯的OAuthV2类实例,再转成通用token并存储
       tencentAuthV2 = (OAuthV2) data.getExtras().getSerializable("oauth");
       CommonOAuth2AccessToken token = new CommonOAuth2AccessToken();
       token.setToken(tencentAuthV2.getAccessToken());
       // 腾讯的过期时间需要转换
       token.setExpiresIn(
           System.currentTimeMillis() + Long.parseLong(tencentAuthV2.getExpiresIn()) * 1000 + "");
       token.setOpenId(tencentAuthV2.getOpenid());
       token.setOpenKey(tencentAuthV2.getOpenkey());
       AccessTokenKeeper.keepAccessToken(
           this, token, AccessTokenKeeper.PREFERENCES_NAME_TOKEN_TENCENT);
       // 更改运行时数据
       RunningData.tencentTokenState = Constants.oauth.HAS_AUTHORIZED;
       RunningData.tencentAccessToken = token;
       // 更改运行时腾讯接口调用对象
       RunningData.oAuthV2 =
           new OAuthV2(
               Constants.tencent.clientId,
               Constants.tencent.clientSecret,
               Constants.tencent.redirectUri);
       RunningData.oAuthV2.setAccessToken(token.getToken());
       RunningData.oAuthV2.setOpenid(token.getOpenId());
       RunningData.oAuthV2.setOpenkey(token.getOpenKey());
       // 发送更新UI的消息
       tencentOAuthCallbackHandler.sendEmptyMessage(TENCENT_OAUTH_SUCCESS);
     }
   }
 }
Esempio n. 2
0
 @Override
 public void onClick(View v) {
   switch (item) {
     case AUTH_MANAGE_IMG_SINA:
       AccessTokenKeeper.clear(MainActivity.this, AccessTokenKeeper.PREFERENCES_NAME_TOKEN_SINA);
       // 退登要清除cookie
       CookieSyncManager.createInstance(getApplicationContext());
       CookieManager.getInstance().removeAllCookie();
       Toast.makeText(MainActivity.this, "已取消绑定", Toast.LENGTH_SHORT).show();
       sinaTokenStateTextView.setText(Constants.oauth.NOT_AUTHORIZED);
       sinaTokenStateImageView.setVisibility(View.INVISIBLE);
       // 更改运行时数据
       RunningData.sinaTokenState = Constants.oauth.NOT_AUTHORIZED;
       break;
     case AUTH_MANAGE_IMG_TENCENT:
       AccessTokenKeeper.clear(
           MainActivity.this, AccessTokenKeeper.PREFERENCES_NAME_TOKEN_TENCENT);
       Toast.makeText(MainActivity.this, "已取消绑定", Toast.LENGTH_SHORT).show();
       tencentTokenStateTextView.setText(Constants.oauth.NOT_AUTHORIZED);
       tencentTokenStateImageView.setVisibility(View.INVISIBLE);
       // 更改运行时数据
       RunningData.tencentTokenState = Constants.oauth.NOT_AUTHORIZED;
       break;
     case AUTH_MANAGE_IMG_RENREN:
       AccessTokenKeeper.clear(
           MainActivity.this, AccessTokenKeeper.PREFERENCES_NAME_TOKEN_RENREN);
       // 人人SDK的特殊性,得把根本性的那个preference删了
       // Logout
       renren.logout(MainActivity.this);
       AccessTokenKeeper.clear(MainActivity.this, "renren_sdk_config");
       Toast.makeText(MainActivity.this, "已取消绑定", Toast.LENGTH_SHORT).show();
       renrenTokenStateTextView.setText(Constants.oauth.NOT_AUTHORIZED);
       renrenTokenStateImageView.setVisibility(View.INVISIBLE);
       // 更改运行时数据
       RunningData.renrenTokenState = Constants.oauth.NOT_AUTHORIZED;
       break;
   }
 }