Android SDK Version
  • java.lang.Object
    • com.facebook.AccessToken

public final class AccessToken
extends java.lang.Object
This class represents an immutable access token for using Facebook APIs. It also includes associated metadata such as expiration date and permissions.
For more information on access tokens, see Access Tokens.
Nested Class Summary
Modifier and TypeClass and Description
static interface AccessToken.AccessTokenCreationCallback
A callback for creating an access token from a NativeLinkingIntent
static interface AccessToken.AccessTokenRefreshCallback 
Field Summary
Modifier and TypeField and Description
static java.lang.StringACCESS_TOKEN_KEY 
static <any>CREATOR 
static java.lang.StringDATA_ACCESS_EXPIRATION_TIME 
static java.lang.StringEXPIRES_IN_KEY 
static java.lang.StringUSER_ID_KEY 
Constructor Summary
Constructor and Description
AccessToken(java.lang.String accessToken, java.lang.String applicationId, java.lang.String userId, java.util.Collection<java.lang.String> permissions, java.util.Collection<java.lang.String> declinedPermissions, java.util.Collection<java.lang.String> expiredPermissions, AccessTokenSource accessTokenSource, java.util.Date expirationTime, java.util.Date lastRefreshTime, java.util.Date dataAccessExpirationTime)
Creates a new AccessToken using the supplied information from a previously-obtained access token (for instance, from an already-cached access token obtained prior to integration with the Facebook SDK).
Method Summary
Modifier and TypeMethod and Description
static voidcreateFromNativeLinkingIntent(Intent intent, java.lang.String applicationId, AccessToken.AccessTokenCreationCallback accessTokenCallback)
Creates a new AccessToken using the information contained in an Intent populated by the Facebook application in order to launch a native link.
intdescribeContents() 
booleanequals(java.lang.Object other) 
java.lang.StringgetApplicationId()
Gets the ID of the Facebook Application associated with this access token.
static AccessTokengetCurrentAccessToken()
Getter for the access token that is current for the application.
java.util.DategetDataAccessExpirationTime()
Gets the date at which user data access expires.
java.util.Set<java.lang.String>getDeclinedPermissions()
Gets the list of permissions declined by the user with this access token.
java.util.Set<java.lang.String>getExpiredPermissions()
Gets the list of permissions that were expired with this access token.
java.util.DategetExpires()
Gets the date at which the access token expires.
java.util.DategetLastRefresh()
Gets the date at which the token was last refreshed.
java.util.Set<java.lang.String>getPermissions()
Gets the list of permissions associated with this access token.
AccessTokenSourcegetSource()
Gets the AccessTokenSource indicating how this access token was obtained.
java.lang.StringgetToken()
Gets the string representing the access token.
java.lang.StringgetUserId()
Returns the user id for this access token.
inthashCode() 
static booleanisCurrentAccessTokenActive()
Returns whether the current AccessToken is active or not.
static booleanisDataAccessActive() 
booleanisDataAccessExpired()
Shows if the user data access is expired.
booleanisExpired()
Shows if the token is expired.
static voidrefreshCurrentAccessTokenAsync()
Updates the current access token with up to date permissions, and extends the expiration date, if extension is possible.
static voidrefreshCurrentAccessTokenAsync(AccessToken.AccessTokenRefreshCallback callback)
Updates the current access token with up to date permissions, and extends the expiration date, if extension is possible.
static voidsetCurrentAccessToken(AccessToken accessToken)
Setter for the access token that is current for the application.
java.lang.StringtoString() 
voidwriteToParcel(Parcel dest, int flags) 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Field Detail

ACCESS_TOKEN_KEY

public static final java.lang.String ACCESS_TOKEN_KEY

EXPIRES_IN_KEY

public static final java.lang.String EXPIRES_IN_KEY

USER_ID_KEY

public static final java.lang.String USER_ID_KEY

DATA_ACCESS_EXPIRATION_TIME

public static final java.lang.String DATA_ACCESS_EXPIRATION_TIME

CREATOR

public static final <any> CREATOR
Constructor Detail

AccessToken

public AccessToken(java.lang.String accessToken,
                   java.lang.String applicationId,
                   java.lang.String userId,
                   java.util.Collection<java.lang.String> permissions,
                   java.util.Collection<java.lang.String> declinedPermissions,
                   java.util.Collection<java.lang.String> expiredPermissions,
                   AccessTokenSource accessTokenSource,
                   java.util.Date expirationTime,
                   java.util.Date lastRefreshTime,
                   java.util.Date dataAccessExpirationTime)
Creates a new AccessToken using the supplied information from a previously-obtained access token (for instance, from an already-cached access token obtained prior to integration with the Facebook SDK). Note that the caller is asserting that all parameters provided are correct with respect to the access token string; no validation is done to verify they are correct.
Parameters:
accessToken - the access token string obtained from Facebook
applicationId - the ID of the Facebook Application associated with this access token
userId - the id of the user
permissions - the permissions that were requested when the token was obtained (or when it was last reauthorized); may be null if permission set is unknown
declinedPermissions - the permissions that were declined when the token was obtained; may be null if permission set is unknown
expiredPermissions - the permissions that were expired when the token was obtained; may be null if permission set is unknown
accessTokenSource - an enum indicating how the token was originally obtained (in most cases, this will be either AccessTokenSource.FACEBOOK_APPLICATION or AccessTokenSource.WEB_VIEW); if null, FACEBOOK_APPLICATION is assumed.
expirationTime - the expiration date associated with the token; if null, an infinite expiration time is assumed (but will become correct when the token is refreshed)
lastRefreshTime - the last time the token was refreshed (or when it was first obtained); if null, the current time is used.
dataAccessExpirationTime - The time when user data access expires
Method Detail

getCurrentAccessToken

public static AccessToken getCurrentAccessToken()
Getter for the access token that is current for the application.
Returns:
The access token that is current for the application.

isCurrentAccessTokenActive

public static boolean isCurrentAccessTokenActive()
Returns whether the current AccessToken is active or not.
Returns:
true if the current AccessToken exists and has not expired; false, otherwise.

isDataAccessActive

public static boolean isDataAccessActive()

setCurrentAccessToken

public static void setCurrentAccessToken(AccessToken accessToken)
Setter for the access token that is current for the application.
Parameters:
accessToken - The access token to set.

refreshCurrentAccessTokenAsync

public static void refreshCurrentAccessTokenAsync()
Updates the current access token with up to date permissions, and extends the expiration date, if extension is possible.

refreshCurrentAccessTokenAsync

public static void refreshCurrentAccessTokenAsync(AccessToken.AccessTokenRefreshCallback callback)
Updates the current access token with up to date permissions, and extends the expiration date, if extension is possible.
Parameters:
callback -

getToken

public java.lang.String getToken()
Gets the string representing the access token.
Returns:
the string representing the access token

getExpires

public java.util.Date getExpires()
Gets the date at which the access token expires.
Returns:
the expiration date of the token

getDataAccessExpirationTime

public java.util.Date getDataAccessExpirationTime()
Gets the date at which user data access expires.
Returns:
the expiration date of the token

getPermissions

public java.util.Set<java.lang.String> getPermissions()
Gets the list of permissions associated with this access token. Note that the most up-to-date list of permissions is maintained by Facebook, so this list may be outdated if permissions have been added or removed since the time the AccessToken object was created. For more information on permissions, see https://developers.facebook.com/docs/reference/login/#permissions.
Returns:
a read-only list of strings representing the permissions granted via this access token

getDeclinedPermissions

public java.util.Set<java.lang.String> getDeclinedPermissions()
Gets the list of permissions declined by the user with this access token. It represents the entire set of permissions that have been requested and declined. Note that the most up-to-date list of permissions is maintained by Facebook, so this list may be outdated if permissions have been granted or declined since the last time an AccessToken object was created.
Returns:
a read-only list of strings representing the permissions declined by the user

getExpiredPermissions

public java.util.Set<java.lang.String> getExpiredPermissions()
Gets the list of permissions that were expired with this access token.
Returns:
a read-only list of strings representing the expired permissions

getSource

public AccessTokenSource getSource()
Gets the AccessTokenSource indicating how this access token was obtained.
Returns:
the enum indicating how the access token was obtained

getLastRefresh

public java.util.Date getLastRefresh()
Gets the date at which the token was last refreshed. Since tokens expire, the Facebook SDK will attempt to renew them periodically.
Returns:
the date at which this token was last refreshed

getApplicationId

public java.lang.String getApplicationId()
Gets the ID of the Facebook Application associated with this access token.
Returns:
the application ID

getUserId

public java.lang.String getUserId()
Returns the user id for this access token.
Returns:
The user id for this access token.

createFromNativeLinkingIntent

public static void createFromNativeLinkingIntent(Intent intent,
                                                 java.lang.String applicationId,
                                                 AccessToken.AccessTokenCreationCallback accessTokenCallback)
Creates a new AccessToken using the information contained in an Intent populated by the Facebook application in order to launch a native link. For more information on native linking, please see https://developers.facebook.com/docs/mobile/android/deep_linking/.
Parameters:
intent - the Intent that was used to start an Activity; must not be null
applicationId - the ID of the Facebook Application associated with this access token

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

isExpired

public boolean isExpired()
Shows if the token is expired.
Returns:
true if the token is expired.

isDataAccessExpired

public boolean isDataAccessExpired()
Shows if the user data access is expired.
Returns:
true if the data access is expired.

describeContents

public int describeContents()

writeToParcel

public void writeToParcel(Parcel dest,
                          int flags)