本文整理汇总了Java中com.facebook.AccessToken.refreshCurrentAccessTokenAsync方法的典型用法代码示例。如果您正苦于以下问题:Java AccessToken.refreshCurrentAccessTokenAsync方法的具体用法?Java AccessToken.refreshCurrentAccessTokenAsync怎么用?Java AccessToken.refreshCurrentAccessTokenAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.AccessToken
的用法示例。
在下文中一共展示了AccessToken.refreshCurrentAccessTokenAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: refreshFacebookCredentials
import com.facebook.AccessToken; //导入方法依赖的package包/类
/**
* Refresh cognito credentials based on identity token previously obtained from Facebook
* @param onCompletion a runnable that will be executed once the credentials have been successfully renewed
*/
private void refreshFacebookCredentials(Runnable onCompletion) {
Log.v(TAG, "Will try to refresh Facebook token as session has expired...");
final AccessToken accessToken = AccessToken.getCurrentAccessToken();
if (!accessToken.isExpired()) {
Log.v(TAG, String.format(" -> Facebook token is not expired (expiration %s)...", SimpleDateFormat.getInstance().format(accessToken.getExpires())));
String token = accessToken.getToken();
Map<String, String> logins = new HashMap<>();
logins.put(FACEBOOK_LOGIN, token);
Log.v(TAG, " -> will refresh login for " + FACEBOOK_LOGIN);
// Refreshing session credentials (must be asynchronous)...
new RefreshTokenTask(onCompletion).execute(logins);
// We use the opportunity to refresh the Facebook token
Date now = new Date();
if (accessToken.getLastRefresh().getTime() < (now.getTime() - 7 * 86400)) {
Log.v(TAG, " -> triggering async facebook token refresh");
AccessToken.refreshCurrentAccessTokenAsync();
}
} else {
Log.v(TAG, String.format(" -> Facebook token is expired (expiration %s)...", SimpleDateFormat.getInstance().format(accessToken.getExpires())));
//User has to sign in to refresh an elapsed facebook token
// TODO onCompletion is ignored (should be dealt with in onActivityResult)
Intent intent = new Intent(this, SignInActivity.class);
this.startActivity(intent);
}
}
示例2: refreshFacebookAccessToken
import com.facebook.AccessToken; //导入方法依赖的package包/类
/**
* Refresh Facebook Access Token.
* According to Facebook's docs this may or may not extend the expiration date.
* Must be called from the UI Thread.
*/
public static void refreshFacebookAccessToken() {
AccessToken.refreshCurrentAccessTokenAsync();
}