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.
扩展: | Object |
执行: | Parcelable |
应用安装包: | facebook |
AccessToken(String, String, String, Collection, Collection, AccessTokenSource, Date, Date)
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.
public AccessToken(String accessToken, String applicationId, String userId, Collection permissions, Collection declinedPermissions, AccessTokenSource accessTokenSource, Date expirationTime, Date lastRefreshTime)
参数 | 描述 |
---|---|
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 |
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. |
getCurrentAccessToken()
Getter for the access token that is current for the application.
public static AccessToken getCurrentAccessToken()
setCurrentAccessToken(AccessToken)
Setter for the access token that is current for the application.
public static void setCurrentAccessToken(AccessToken accessToken)
参数 | 描述 |
---|---|
accessToken | The access token to set. |
refreshCurrentAccessTokenAsync()
Updates the current access token with up to date permissions, and extends the expiration date, if extension is possible.
This function must be run from the UI thread.
public static void refreshCurrentAccessTokenAsync()
createFromNativeLinkingIntent(Intent, String, AccessTokenCreationCallback)
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/.
public static void createFromNativeLinkingIntent(Intent intent, String applicationId, AccessTokenCreationCallback accessTokenCallback)
参数 | 描述 |
---|---|
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 |
accessTokenCallback |
getToken()
Gets the string representing the access token.
public String getToken()
getExpires()
Gets the date at which the access token expires.
public Date getExpires()
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.
public Set getPermissions()
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.
public Set getDeclinedPermissions()
getSource()
Gets the AccessTokenSource indicating how this access token was obtained.
public AccessTokenSource getSource()
getLastRefresh()
Gets the date at which the token was last refreshed. Since tokens expire, the Facebook SDK will attempt to renew them periodically.
public Date getLastRefresh()
getApplicationId()
Gets the ID of the Facebook Application associated with this access token.
public String getApplicationId()
getUserId()
Returns the user id for this access token.
public String getUserId()
isExpired()
Shows if the token is expired.
public boolean isExpired()
describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
public int describeContents()
describeContents()
public int describeContents()
writeToParcel(Parcel, int)
Flatten this object in to a Parcel.
public void writeToParcel(Parcel dest, int flags)
参数 | 描述 |
---|---|
dest | The Parcel in which the object should be written. |
flags | Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE. |
writeToParcel(Parcel, int)
public void writeToParcel(Parcel dest, int flags)
参数 | 描述 |
---|---|
dest | |
flags |
ACCESS_TOKEN_KEY
public static final String ACCESS_TOKEN_KEY
EXPIRES_IN_KEY
public static final String EXPIRES_IN_KEY
USER_ID_KEY
public static final String USER_ID_KEY
CREATOR
public static final Creator CREATOR