Reputation: 63
I am developing a product for iPhone and Android for Facebook users. Since "offline_access" permissions had been removed from Facebook Graph API, and the life time of an access token can only extended to 60 days, I want to know if there is a way to refresh access token automatically. Anyone has a good idea?
Upvotes: 3
Views: 1658
Reputation: 12641
In ios you can extend token using following methods:
- (void)extendAccessToken {
if (_isExtendingAccessToken) {
return;
}
_isExtendingAccessToken = YES;
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"auth.extendSSOAccessToken", @"method", nil];
[self requestWithParams:params andDelegate:self];
}
//+ * Calls extendAccessToken if shouldExtendAccessToken returns YES.
- (void)extendAccessTokenIfNeeded {
if ([self shouldExtendAccessToken]) {
[self extendAccessToken];
}
}
// Returns YES if the last time a new token was obtained was over 24 hours ago.
- (BOOL)shouldExtendAccessToken {
if ([self isSessionValid]){
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [calendar components:NSHourCalendarUnit fromDate:_lastAccessTokenUpdatetoDate:[NSDate date]options:0];
if (components.hour >= kTokenExtendThreshold) {
return YES;
}
}
return NO;
}
as given in this Link
Upvotes: 1
Reputation: 5515
You no need to care about refresh the token, facebook sdk will take care of that automatically
Upvotes: 1