Posting a photo to Facebook fan page as user. iOS

2019-06-11 04:57发布

问题:


I'm trying to post a photo to Facebook page from user using Facebook SDK 3.1.
When I'm using the following code to create upload image request:

FBRequest *uploadPhotoRequest = [FBRequest requestWithGraphPath:@"/${FAN_PAGE_ID}/photos/" parameters:[NSDictionary dictionaryWithObjectsAndKeys:self.imageToShare, @"source", nil] HTTPMethod:@"POST"];

Image goes directly to user's timeline, not the page's one.

But when I'm posting a link:

FBRequest *request = [FBRequest requestWithGraphPath:@"/${FAN_PAGE_ID}/feed/" parameters:[NSDictionary dictionaryWithObjectsAndKeys:@"http://stackoverflow.com", @"link", nil] HTTPMethod:@"POST"];

Link posts correctly to the facebook page.

To open a session I'm using code:

[FBSession openActiveSessionWithPermissions:[NSArray arrayWithObjects:@"publish_stream", @"photo_upload", nil]
                               allowLoginUI:YES
                          completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
...
                          }];

I know that openActiveSessionWithPermissions is deprecated, using it for equal SSO behaviour on iOS 5 and 6.

UPDATE

Or is it possible to upload a photo with access token substitution? Using page access token instead of user access token. If yes, how can I get page access token programmatically without forcing user to log in as page administrator?

What would you advise me to do?
Thanks!

BR. Eugene.

回答1:

https://developers.facebook.com/docs/reference/api/page/#photos says,

“You can post photos to a Page's Wall by issuing an HTTP POST request to PAGE_ID/photos with the publish_stream and manage_pages permissions […]”

Sounds like a “normal” user is not allowed to post images to a page’s wall via the API.