I am working on getting posts from a public Facebook page using the Facebook Graph API, without the user logging in. Using the steps from here I got the Token I would need since the end-user is not logging in, and the page is public. In my app, I have the following:
-(IBAction)testing {
NSString *token = @"MYAccessToken";
FBSession* session = [[FBSession alloc] initWithPermissions:@[@"manage_pages"]];
FBAccessTokenData* tokenData =
[FBAccessTokenData createTokenFromString:token
permissions:@[@"manage_pages"]
expirationDate:nil
loginType:FBSessionLoginTypeNone
refreshDate:nil];
[session openFromAccessTokenData:tokenData completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if ([session isOpen]) {
[self performGraph];
}
}];
}
-(void)performGraph {
NSLog(@"Go");
[FBRequestConnection startWithGraphPath:@"/{your-page}/posts"
parameters:nil
HTTPMethod:@"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(@"Result%@", result);
/* handle the result */
}];
}
It runs the method performGraph as I can see it in my Console, leading me to believe that the FBSession must be open, since that is where it runs it. However, I get the following error message in FBSDKLog: Error for request to endpoint '/{your-page}/posts': An open FBSession must be specified for calls to this endpoint.
If the FBSession isn't open, it shouldn't be even attempting to perform the Graph API call, yet it tells me it needs an open FBSession. Can someone help me out here a bit?