Facebook iOS SDK placement as page

In my iOS app, I want to post a Facebook page on a Facebook page.

I retrieve the page access tokens through the "me / accounts" endpoint through the user. However, I'm not sure how to create an FBSession using this page access token to create a submit request.

The page access current is a string, and I got it right by asking the user for "manage_pages" and "publish_stream" permissions.

Is there an easy way to do this? I looked at fetchFBAccessTokenData but don't know how I can use it.

+4
source share
2 answers

The answer - and it took me a long time to find - initWithSession:FBSession.activeSession should be initWithSession:nil , and the access token should be set in the parameters NSDictionary field as [parameters setObject:yourAccessToken forKey:@"access_token"] . The access token in FBSession.activeSession overrides the access_token parameter in the parameters (which it should not IMHO), making the message appear as a fan post, rather than a page as a page.

 [d addObject:yourFetchedAccessTokenString forKey:@"access_token"]; FBRequest *request = [[FBRequest alloc] initWithSession:nil graphPath:graphPath parameters:d HTTPMethod:@"POST"]; 

Of course, there are other problems, for example, how long the access token will remain idle, which requires token caching schemes: https://developers.facebook.com/docs/howtos/token-caching-ios-sdk/

Found the answer here: https://github.com/facebook/facebook-ios-sdk/pull/483

+4
source

Thousand thanks for the James O'Brien code. In addition to this, you may need the code below:

 FBRequestConnection *con = [[FBRequestConnection alloc] init]; [con addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error){ NSLog(@"facebook result >> %@", result); [self cancelfbshare:nil]; }]; [con start]; 
+1
source

Source: https://habr.com/ru/post/1480012/


All Articles