Reputation: 35
I use facebook sdk on my iOS app to sign-in and sharing story.
Sharing story on Facebook feature was working properly but today it's not working. I don't know why it's not working because no code changes related to that feature.
The followings are the code that requests publish_actions permission.
// Request publish_actions
[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
// Permission not granted, tell the user we will not publish
} else {
// Permission granted
}
} else {
NSLog(@"DEBUG: error = %@", error);
// There was an error, handle it
// See https://developers.facebook.com/docs/ios/errors/
}
}];
The error message is as followings,
Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. com.facebook.sdk:ErrorReauthorizeFailedReasonSessionClosed"
UserInfo=0xXXXXXXXXX {
com.facebook.sdk:ErrorLoginFailedReason=
com.facebook.sdk:ErrorReauthorizeFailedReasonSessionClosed,
NSLocalizedFailureReason=
com.facebook.sdk:ErrorReauthorizeFailedReasonSessionClosed,
com.facebook.sdk:ErrorSessionKey= ... >
}
If anybody knows this, please help me.
** Facebook SDK version is 3.18, and publish_actions item is already approved in developer.facebook.com
Upvotes: 2
Views: 96
Reputation: 1159
You can use FBSDKAccessToken
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {
[self doShare];
} else {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
// Process error
} else if (result.isCancelled) {
// Handle cancellations
} else {
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if ([result.grantedPermissions containsObject:@"publish_actions"]) {
// Do work
[self doShare];
}
}
}];
}
where doShare
-(void) doShare{
NSString *url = [NSString stringWithFormat:@"http://example.com/locations/%d",1];
NSDictionary *properties = @{
@"your action" :url
};
[[[FBSDKGraphRequest alloc]
initWithGraphPath:@"me/example-staging:something"
parameters: properties
HTTPMethod:@"POST"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
// NSLog(@"Post id:%@", result[@"id"]);
}
}];
Upvotes: 0