Post as a fan page on iOS Facebook SDK 3.0
-
01-07-2021 - |
Question
I'm trying to post to a fan page as the fan page, not as the user.
On the old SDK, I simply asked for "me/accounts" and received the access token. Now I can do the same, but I have no way to use that Token, since FBRequest takes its access token from the active session (also, it's a readonly property).
Does anyone knows how to create another session or simply FBRequests with the page token?
Thanks!
Solution
Found a solution, it's not the cleanest, but it's working:
Note: Updated for Facebook SDK 3.2+
- (void)postAsFanPageWithToken:(NSString *)aFanPageToken {
if (self.selectedFanPage == nil) {
self.userAccessToken = [FBSession activeSession].accessTokenData.accessToken;
}
//Using KVC, since it is a readonly property
[[FBSession activeSession].accessTokenData setValue:aFanPageToken forKey:@"accessToken"];
}
- (void)postAsMe {
if (self.userAccessToken == nil) {
return; //Already posting as me
}
[[FBSession activeSession].accessTokenData setValue:self.userAccessToken forKey:@"accessToken"];
self.userAccessToken = nil;
}
// Make sure you cleanup on logout
- (void)logout {
self.userAccessToken = nil;
[[FBSession activeSession] closeAndClearTokenInformation];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow