本文整理匯總了Java中com.facebook.AccessToken.getToken方法的典型用法代碼示例。如果您正苦於以下問題:Java AccessToken.getToken方法的具體用法?Java AccessToken.getToken怎麽用?Java AccessToken.getToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.facebook.AccessToken
的用法示例。
在下文中一共展示了AccessToken.getToken方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createFromTokenWithRefreshedPermissions
import com.facebook.AccessToken; //導入方法依賴的package包/類
private static AccessToken createFromTokenWithRefreshedPermissions(
AccessToken token,
Collection<String> grantedPermissions,
Collection<String> declinedPermissions) {
return new AccessToken(
token.getToken(),
token.getApplicationId(),
token.getUserId(),
grantedPermissions,
declinedPermissions,
token.getSource(),
token.getExpires(),
token.getLastRefresh());
}
示例2: getToken
import com.facebook.AccessToken; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public String getToken() {
AccessToken accessToken = getSignedInToken();
if (accessToken != null) {
return accessToken.getToken();
}
return null;
}
示例3: refreshToken
import com.facebook.AccessToken; //導入方法依賴的package包/類
@Override
public String refreshToken() {
AccessToken accessToken = getSignedInToken();
// getSignedInToken() returns null if token is expired.
if (accessToken == null) {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
// refreshes access token in the background.
AccessToken.refreshCurrentAccessTokenAsync();
}
});
// There is no method to check the status of the refresh operation, so we have to resort to polling.
int retries = 0;
while (accessToken == null && (retries++ < REFRESH_TOKEN_POLLING_RETRIES)) {
try {
Thread.sleep(REFRESH_TOKEN_POLLING_INTERVAL_MS);
} catch (final InterruptedException ex) {
Log.w(LOG_TAG, "Unexpected Interrupt of refreshToken()", ex);
throw new RuntimeException(ex);
}
accessToken = getSignedInToken();
}
if (accessToken == null) {
return null;
}
}
return accessToken.getToken();
}
示例4: 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);
}
}
示例5: tryAuthorize
import com.facebook.AccessToken; //導入方法依賴的package包/類
@Override
boolean tryAuthorize(final LoginClient.Request request) {
Bundle parameters = new Bundle();
if (!Utility.isNullOrEmpty(request.getPermissions())) {
String scope = TextUtils.join(",", request.getPermissions());
parameters.putString(ServerProtocol.DIALOG_PARAM_SCOPE, scope);
addLoggingExtra(ServerProtocol.DIALOG_PARAM_SCOPE, scope);
}
DefaultAudience audience = request.getDefaultAudience();
parameters.putString(
ServerProtocol.DIALOG_PARAM_DEFAULT_AUDIENCE, audience.getNativeProtocolAudience());
AccessToken previousToken = AccessToken.getCurrentAccessToken();
String previousTokenString = previousToken != null ? previousToken.getToken() : null;
if (previousTokenString != null
&& (previousTokenString.equals(loadCookieToken()))) {
parameters.putString(
ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN,
previousTokenString);
// Don't log the actual access token, just its presence or absence.
addLoggingExtra(
ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN,
AppEventsConstants.EVENT_PARAM_VALUE_YES);
} else {
// The call to clear cookies will create the first instance of CookieSyncManager if
// necessary
Utility.clearFacebookCookies(loginClient.getActivity());
addLoggingExtra(
ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN,
AppEventsConstants.EVENT_PARAM_VALUE_NO);
}
WebDialog.OnCompleteListener listener = new WebDialog.OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
onWebDialogComplete(request, values, error);
}
};
e2e = LoginClient.getE2E();
addLoggingExtra(ServerProtocol.DIALOG_PARAM_E2E, e2e);
FragmentActivity fragmentActivity = loginClient.getActivity();
WebDialog.Builder builder = new AuthDialogBuilder(
fragmentActivity,
request.getApplicationId(),
parameters)
.setE2E(e2e)
.setIsRerequest(request.isRerequest())
.setOnCompleteListener(listener)
.setTheme(FacebookSdk.getWebDialogTheme());
loginDialog = builder.build();
FacebookDialogFragment dialogFragment = new FacebookDialogFragment();
dialogFragment.setRetainInstance(true);
dialogFragment.setDialog(loginDialog);
dialogFragment.show(fragmentActivity.getSupportFragmentManager(),
FacebookDialogFragment.TAG);
return true;
}
示例6: AccessTokenAppIdPair
import com.facebook.AccessToken; //導入方法依賴的package包/類
AccessTokenAppIdPair(AccessToken accessToken) {
this(accessToken.getToken(), FacebookSdk.getApplicationId());
}