本文整理匯總了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();
}