iOS SDK Version

FBSDKAccessToken

@interfaceFBSDKAccessToken:NSObject<FBSDKCopying,NSSecureCoding>
Represents an immutable access token for using Facebook services.
  • The “global” access token that represents the currently logged in user.
    The currentAccessToken is a convenient representation of the token of the current user and is used by other SDK components (like FBSDKLoginManager).

    Declaration

    Objective-C
    @property(class,nonatomic,copy,readwrite,nullable)FBSDKAccessToken*currentAccessToken;
    Swift
    @NSCopyingclassvarcurrent:AccessToken?{getset}
  • Returns YES if currentAccessToken is not nil AND currentAccessToken is not expired

    Declaration

    Objective-C
    @property(class,nonatomic,assign,unsafe_unretained,readonly,getter=isCurrentAccessTokenActive)BOOLcurrentAccessTokenIsActive;
    Swift
    classvarisCurrentAccessTokenActive:Bool{get}
  • Returns the app ID.

    Declaration

    Objective-C
    @property(nonatomic,copy,readonly)NSString*_NonnullappID;
    Swift
    varappID:String{get}
  • Returns the expiration date for data access

    Declaration

    Objective-C
    @property(nonatomic,copy,readonly)NSDate*_NonnulldataAccessExpirationDate;
    Swift
    vardataAccessExpirationDate:Date{get}
  • Returns the known declined permissions.

    Declaration

    Objective-C
    @property(nonatomic,copy,readonly)NS_REFINED_FOR_SWIFTNSSet<NSString*>*declinedPermissions;
  • Returns the known declined permissions.

    Declaration

    Objective-C
    @property(nonatomic,copy,readonly)NS_REFINED_FOR_SWIFTNSSet<NSString*>*expiredPermissions;
  • Returns the expiration date.

    Declaration

    Objective-C
    @property(nonatomic,copy,readonly)NSDate*_NonnullexpirationDate;
    Swift
    varexpirationDate:Date{get}
  • Returns the known granted permissions.

    Declaration

    Objective-C
    @property(nonatomic,copy,readonly)NS_REFINED_FOR_SWIFTNSSet<NSString*>*permissions;
  • Returns the date the token was last refreshed.

    Declaration

    Objective-C
    @property(nonatomic,copy,readonly)NSDate*_NonnullrefreshDate;
    Swift
    varrefreshDate:Date{get}
  • Returns the opaque token string.

    Declaration

    Objective-C
    @property(nonatomic,copy,readonly)NSString*_NonnulltokenString;
    Swift
    vartokenString:String{get}
  • Returns the user ID.

    Declaration

    Objective-C
    @property(nonatomic,copy,readonly)NSString*_NonnulluserID;
    Swift
    varuserID:String{get}
  • The graph domain where this access token is valid.

    Declaration

    Objective-C
    @property(nonatomic,copy,readonly)NSString*_NonnullgraphDomain;
    Swift
    vargraphDomain:String{get}
  • Returns whether the access token is expired by checking its expirationDate property

    Declaration

    Objective-C
    @property(nonatomic,assign,unsafe_unretained,readonly,getter=isExpired)BOOLexpired;
    Swift
    varisExpired:Bool{get}
  • Returns whether user data access is still active for the given access token

    Declaration

    Objective-C
    @property(nonatomic,assign,unsafe_unretained,readonly,getter=isDataAccessExpired)BOOLdataAccessExpired;
    Swift
    varisDataAccessExpired:Bool{get}
  • Unavailable
    Undocumented

    Declaration

    Objective-C
    -(instancetype)initNS_UNAVAILABLE;
  • Unavailable
    Undocumented

    Declaration

    Objective-C
    +(instancetype)newNS_UNAVAILABLE;
  • Initializes a new instance.
    This initializer should only be used for advanced apps that manage tokens explicitly. Typical login flows only need to use FBSDKLoginManager along with +currentAccessToken.

    Declaration

    Objective-C
    -(nonnullinstancetype)initWithTokenString:(nonnullNSString*)tokenStringpermissions:(nonnullNSArray<NSString*>*)permissionsdeclinedPermissions:(nonnullNSArray<NSString*>*)declinedPermissionsexpiredPermissions:(nonnullNSArray<NSString*>*)expiredPermissionsappID:(nonnullNSString*)appIDuserID:(nonnullNSString*)userIDexpirationDate:(nullableNSDate*)expirationDaterefreshDate:(nullableNSDate*)refreshDatedataAccessExpirationDate:(nullableNSDate*)dataAccessExpirationDate;
    Swift
    init(tokenString:String,permissions:[String],declinedPermissions:[String],expiredPermissions:[String],appID:String,userID:String,expirationDate:Date?,refreshDate:Date?,dataAccessExpirationDate:Date?)

    Parameters

    tokenString
    the opaque token string.
    permissions
    the granted permissions. Note this is converted to NSSet and is only an NSArray for the convenience of literal syntax.
    declinedPermissions
    the declined permissions. Note this is converted to NSSet and is only an NSArray for the convenience of literal syntax.
    expiredPermissions
    the expired permissions. Note this is converted to NSSet and is only an NSArray for the convenience of literal syntax.
    appID
    the app ID.
    userID
    the user ID.
    expirationDate
    the optional expiration date (defaults to distantFuture).
    refreshDate
    the optional date the token was last refreshed (defaults to today).
    dataAccessExpirationDate
    the date which data access will expire for the given user (defaults to distantFuture).
  • Convenience initializer.
    This initializer should only be used for advanced apps that manage tokens explicitly. Typical login flows only need to use FBSDKLoginManager along with +currentAccessToken.

    Declaration

    Objective-C
    -(nonnullinstancetype)initWithTokenString:(nonnullNSString*)tokenStringpermissions:(nonnullNSArray<NSString*>*)permissionsdeclinedPermissions:(nonnullNSArray<NSString*>*)declinedPermissionsexpiredPermissions:(nonnullNSArray<NSString*>*)expiredPermissionsappID:(nonnullNSString*)appIDuserID:(nonnullNSString*)userIDexpirationDate:(nullableNSDate*)expirationDaterefreshDate:(nullableNSDate*)refreshDatedataAccessExpirationDate:(nullableNSDate*)dataAccessExpirationDategraphDomain:(nullableNSString*)graphDomain;
    Swift
    convenienceinit(tokenString:String,permissions:[String],declinedPermissions:[String],expiredPermissions:[String],appID:String,userID:String,expirationDate:Date?,refreshDate:Date?,dataAccessExpirationDate:Date?,graphDomain:String?)

    Parameters

    tokenString
    the opaque token string.
    permissions
    the granted permissions. Note this is converted to NSSet and is only an NSArray for the convenience of literal syntax.
    declinedPermissions
    the declined permissions. Note this is converted to NSSet and is only an NSArray for the convenience of literal syntax.
    expiredPermissions
    the expired permissions. Note this is converted to NSSet and is only an NSArray for the convenience of literal syntax.
    appID
    the app ID.
    userID
    the user ID.
    expirationDate
    the optional expiration date (defaults to distantFuture).
    refreshDate
    the optional date the token was last refreshed (defaults to today).
    dataAccessExpirationDate
    the date which data access will expire for the given user (defaults to distantFuture).
    graphDomain
    the domain this access token can be used in.
  • Convenience getter to determine if a permission has been granted

    Declaration

    Objective-C
    -(BOOL)hasGranted:(nonnullNSString*)permission;
    Swift
    funchasGranted(permission:String)->Bool

    Parameters

    permission
    The permission to check.
  • Compares the receiver to another FBSDKAccessToken

    Declaration

    Objective-C
    -(BOOL)isEqualToAccessToken:(nonnullFBSDKAccessToken*)token;
    Swift
    funcisEqual(totoken:AccessToken)->Bool

    Parameters

    token
    The other token

    Return Value

    YES if the receiver’s values are equal to the other token’s values; otherwise NO
  • Refresh the current access token’s permission state and extend the token’s expiration date, if possible.
    On a successful refresh, the currentAccessToken will be updated so you typically only need to observe the FBSDKAccessTokenDidChangeNotification notification.
    If a token is already expired, it cannot be refreshed.

    Declaration

    Objective-C
    +(void)refreshCurrentAccessToken:(nullableFBSDKGraphRequestBlock)completionHandler;
    Swift
    classfuncrefreshCurrentAccessToken(_completionHandler:GraphRequestBlock?=nil)

    Parameters

    completionHandler
    an optional callback handler that can surface any errors related to permission refreshing.