本文整理汇总了Java中com.sina.weibo.sdk.auth.Oauth2AccessToken类的典型用法代码示例。如果您正苦于以下问题:Java Oauth2AccessToken类的具体用法?Java Oauth2AccessToken怎么用?Java Oauth2AccessToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Oauth2AccessToken类属于com.sina.weibo.sdk.auth包,在下文中一共展示了Oauth2AccessToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onComplete
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
@Override
public void onComplete(Bundle values) {
// 从 Bundle 中解析 Token
mAccessToken = Oauth2AccessToken.parseAccessToken(values);
if (mAccessToken.isSessionValid()) {
// 保存 Token 到 SharedPreferences
TokenKeeper.writeAccessToken(LoginActivity.this, mAccessToken);
Toast.makeText(LoginActivity.this,
"授权成功", Toast.LENGTH_SHORT).show();
new login().execute(UrlConstance.APP_URL + UrlConstance.KEY_LOGIN_INFO + "?usertoken=" + mAccessToken.getToken() + "&usertype=1");
} else {
// 以下几种情况,您会收到 Code:
// 1. 当您未在平台上注册的应用程序的包名与签名时;
// 2. 当您注册的应用程序包名与签名不正确时;
// 3. 当您在平台上注册的包名和签名与您当前测试的应用的包名和签名不匹配时。
String code = values.getString("code");
String message = "授权失败";
if (!TextUtils.isEmpty(code)) {
message = message + "\nObtained the code: " + code;
}
Toast.makeText(LoginActivity.this, message, Toast.LENGTH_LONG).show();
}
}
示例2: onComplete
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
@Override
public void onComplete(Bundle values) {
Log.i(TAG, "AuthListener.onComplete");
Oauth2AccessToken accessToken = Oauth2AccessToken.parseAccessToken(values);
if (accessToken != null && accessToken.isSessionValid()) {
//UsersAPI userAPI=new UsersAPI(accessToken);
//userAPI.show(Long.parseLong(accessToken.getUid()), userListener);
String date = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(
new java.util.Date(accessToken.getExpiresTime()));
System.out.println("uid=" + accessToken.getUid());
System.out.println("access_token=" + accessToken.getToken());
System.out.println("expiresTime=" + date);
AccessTokenKeeper.writeAccessToken(mContext, accessToken);
shareToWeibo();
}
}
示例3: onComplete
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
@Override
public void onComplete(Bundle bundle) {
// 从 Bundle 中解析 Token
Oauth2AccessToken accessToken = Oauth2AccessToken.parseAccessToken(bundle);
if (accessToken.isSessionValid()) {
// save accessToken
WeiboData.writeAccessToken(this, accessToken);
// sign in succeed, show main activity
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
} else {
}
}
示例4: onComplete
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
@Override
public void onComplete(Bundle values) {
if (values == null)
return;
mAccessToken = Oauth2AccessToken.parseAccessToken(values);
if (mAccessToken.isSessionValid()) {
if (authWrap.context == null)
return;
App.getDefault().setValue("sina_auth", true);
if (!TextUtils.isEmpty(mAccessToken.getToken())) {
App.getDefault().setValue("sina_token", mAccessToken.getToken());
}
shareListener.onComplete(ShareType, ShareConstant.SHARE_MEDIA.SINA, values);
if (listener != null) {
listener.onSuccess();
}
} else {
ShareException exception = new ShareException("授权失败");
shareListener.onException(ShareType, ShareConstant.SHARE_MEDIA.SINA, exception);
}
}
示例5: onComplete
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
/**
* 封装了 "access_token","expires_in","refresh_token",并提供了他们的管理功能
*/
@Override
public void onComplete(Bundle values) {
LogUtils.e(TAG,"wb_auth", "complete " + values.toString());
// 从 Bundle 中解析 Token
Oauth2AccessToken mAccessToken = Oauth2AccessToken.parseAccessToken(values);
//从这里获取用户输入的 电话号码信息
//String phoneNum = mAccessToken.getPhoneNum();
if (mAccessToken.isSessionValid()) {
// 授权成功
TokenStoreUtils.saveWbToken(context, mAccessToken);
listener.onAuth(mAccessToken);
} else {
// 以下几种情况,您会收到 Code:
// 1. 当您未在平台上注册的应用程序的包名与签名时;
// 2. 当您注册的应用程序包名与签名不正确时;
// 3. 当您在平台上注册的包名和签名与您当前测试的应用的包名和签名不匹配时。
String code = values.getString("code");
// 授权失败
LogUtils.e(TAG,"wb_auth", "授权失败 " + code);
listener.onException(new SocialException("授权失败 code = " + code));
}
}
示例6: login
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
public void login(Activity activity, SsoHandler ssoHandler, final OnLoginListener loginListener) {
this.loginListener = loginListener;
if (loginListener == null)
return;
WbAuthHelper.auth(activity, ssoHandler, new WbAuthHelper.OnAuthOverListener() {
@Override
public void onAuth(Oauth2AccessToken token) {
getUserInfo(token);
}
@Override
public void onException(SocialException e) {
loginListener.onFailure(e);
}
@Override
public void onCancel() {
loginListener.onCancel();
}
});
}
示例7: writeAccessToken
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
/**
* 保存 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);
}
示例8: doLogin
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
@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();
}
});
}
示例9: parse
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
public static WeiboToken parse(Oauth2AccessToken token) {
WeiboToken target = new WeiboToken();
target.setOpenid(token.getUid());
target.setAccessToken(token.getToken());
target.setRefreshToken(token.getRefreshToken());
target.setPhoneNum(token.getPhoneNum());
return target;
}
示例10: writeAccessToken
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
/**
* 保存 Token 对象到 SharedPreferences。
*
* @param context 应用程序上下文环境
* @param token Token 对象
*/
public static void writeAccessToken(Context context, Oauth2AccessToken token) {
if (null == context || null == token) {
return;
}
SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
Editor editor = pref.edit();
editor.putString(KEY_UID, token.getUid());
editor.putString(KEY_ACCESS_TOKEN, token.getToken());
editor.putLong(KEY_EXPIRES_IN, token.getExpiresTime());
editor.apply();
}
示例11: readAccessToken
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
/**
* 从 SharedPreferences 读取 Token 信息。
*
* @param context 应用程序上下文环境
*
* @return 返回 Token 对象
*/
public static Oauth2AccessToken readAccessToken(Context context) {
if (null == context) {
return null;
}
Oauth2AccessToken token = new Oauth2AccessToken();
SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
token.setUid(pref.getString(KEY_UID, ""));
token.setToken(pref.getString(KEY_ACCESS_TOKEN, ""));
token.setExpiresTime(pref.getLong(KEY_EXPIRES_IN, 0));
return token;
}
示例12: allInOneShare
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
private void allInOneShare(final Context context, SendMultiMessageToWeiboRequest request) {
AuthInfo authInfo = new AuthInfo(context, mSinaAppKey, REDIRECT_URL, SCOPE);
Oauth2AccessToken accessToken = AccessTokenKeeper.readAccessToken(context);
String token = "";
if (accessToken != null) {
token = accessToken.getToken();
}
mSinaAPI.sendRequest((Activity) context, request, authInfo, token, new WeiboAuthListener() {
@Override
public void onWeiboException(WeiboException arg0) {
Toast.makeText(context, context.getString(
R.string.share_failed), Toast.LENGTH_SHORT).show();
}
@Override
public void onComplete(Bundle bundle) {
Oauth2AccessToken newToken = Oauth2AccessToken.parseAccessToken(bundle);
AccessTokenKeeper.writeAccessToken(context, newToken);
Toast.makeText(context, context.getString(
R.string.share_success), Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Toast.makeText(context, context.getString(
R.string.share_cancel), Toast.LENGTH_SHORT).show();
}
});
}
示例13: onComplete
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
@Override
public void onComplete(Bundle values) {
final Oauth2AccessToken accessToken = Oauth2AccessToken.parseAccessToken(values);
if (accessToken != null && accessToken.isSessionValid()) {
AccessTokenKeeper.writeAccessToken(mContext, accessToken);
userAPI = new UsersAPI(mContext, mSinaAppKey, accessToken);
userAPI.show(Long.parseLong(accessToken.getUid()), mListener);
}
}
示例14: onComplete
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
@Override
public void onComplete(Bundle values) {
// 从 Bundle 中解析 Token
mAccessToken = Oauth2AccessToken.parseAccessToken(values);
//从这里获取用户输入的 电话号码信息
String phoneNum = mAccessToken.getPhoneNum();
if (mAccessToken.isSessionValid()) {
// 显示 Token
updateTokenView(false);
// 保存 Token 到 SharedPreferences
AccessTokenKeeper.writeAccessToken(WBAuthActivity.this, mAccessToken);
Toast.makeText(WBAuthActivity.this,
R.string.weibosdk_demo_toast_auth_success, Toast.LENGTH_SHORT).show();
} else {
// 以下几种情况,您会收到 Code:
// 1. 当您未在平台上注册的应用程序的包名与签名时;
// 2. 当您注册的应用程序包名与签名不正确时;
// 3. 当您在平台上注册的包名和签名与您当前测试的应用的包名和签名不匹配时。
String code = values.getString("code");
String message = getString(R.string.weibosdk_demo_toast_auth_failed);
if (!TextUtils.isEmpty(code)) {
message = message + "\nObtained the code: " + code;
}
Toast.makeText(WBAuthActivity.this, message, Toast.LENGTH_LONG).show();
}
}
示例15: writeAccessToken
import com.sina.weibo.sdk.auth.Oauth2AccessToken; //导入依赖的package包/类
/**
* 保存 Token 对象到 SharedPreferences。
*
* @param context 应用程序上下文环境
* @param token Token 对象
*/
public static void writeAccessToken(Context context, Oauth2AccessToken token) {
if (null == context || null == token) {
return;
}
SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
Editor editor = pref.edit();
editor.putString(KEY_UID, token.getUid());
editor.putString(KEY_ACCESS_TOKEN, token.getToken());
editor.putString(KEY_REFRESH_TOKEN, token.getRefreshToken());
editor.putLong(KEY_EXPIRES_IN, token.getExpiresTime());
editor.commit();
}