1
您好,我在我的项目中使用了Facebook SDK 3.8。并在我的应用程序中使用HelloFaceBookSample代码,但在我的应用程序中,我没有Facebook的登录按钮。我已经实现了Facebook的登录流程,登录后我有在Facebook上发布。现在的状态后工作正常,但是当我在Facebook上发布图片它给我FBSession:试图对ios中未打开的会话重新授权权限
an attempt was made reauthorize permissions on an unopened session in ios
代码的错误:
-(void) clickButtonFacebookUsingSDK
{
if (!appdelegate.session.isOpen)
{
appdelegate.session = [[FBSession alloc] init];
[appdelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if(appdelegate.session.isOpen)
{
NSLog(@"calling postdata when session is not open******");
[self postData];
}
}];
}
else
{
NSLog(@"calling postdata when session is open******");
[self postData];
}
}
-(void) postData
{
[self showingActivityIndicator];
UIImage *img = [UIImage imageNamed:@"abc.jpg"];
[self performPublishAction:^{
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
connection.errorBehavior = FBRequestConnectionErrorBehaviorReconnectSession
| FBRequestConnectionErrorBehaviorAlertUser
| FBRequestConnectionErrorBehaviorRetry;
FBRequest *req = [FBRequest requestForUploadPhoto:img];
[req.parameters addEntriesFromDictionary:[NSMutableDictionary dictionaryWithObjectsAndKeys:message3, @"message", nil]];
[connection addRequest:req
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// [self showAlert:@"Photo Post" result:result error:error];
[self showAlert:@"Photo Post" result:result resulterror:error];
if (FBSession.activeSession.isOpen) {
}
}];
[connection start];
}];
}
- (void) performPublishAction:(void (^)(void)) action {
// we defer request for permission to post to the moment of post, then we check for the permission
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound)
{
// if we don't already have the permission, then we request it now
[FBSession.activeSession requestNewPublishPermissions:@[@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error)
{
if (!error) {
action();
} else if (error.fberrorCategory != FBErrorCategoryUserCancelled){
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Permission denied"
message:@"Unable to get permission to post"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}];
} else {
action();
}
}
// UIAlertView helper for post buttons
- (void)showAlert:(NSString *)message result:(id)result resulterror:(NSError *)error
{
NSString *alertMsg;
NSString *alertTitle;
if (error)
{
alertTitle = @"Error";
// Since we use FBRequestConnectionErrorBehaviorAlertUser,
// we do not need to surface our own alert view if there is an
// an fberrorUserMessage unless the session is closed.
if (FBSession.activeSession.isOpen) {
alertTitle = @"Error";
} else {
// Otherwise, use a general "connection problem" message.
alertMsg = @"Operation failed due to a connection problem, retry later.";
}
}
else
{
NSDictionary *resultDict = (NSDictionary *)result;
alertMsg = [NSString stringWithFormat:@"Successfully posted '%@'.", message];
NSString *postId = [resultDict valueForKey:@"id"];
if (!postId) {
postId = [resultDict valueForKey:@"postId"];
}
if (postId) {
alertMsg = [NSString stringWithFormat:@"%@\nPost ID: %@", alertMsg, postId];
}
alertTitle = @"Success";
}
if (alertTitle) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:alertTitle
message:alertMsg
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
[self dismissActivityIndicator];
}
}
它给我的错误中performPublishAction方法。
谁能告诉我是什么问题。我有很多搜索,也发现了很多解决方案,但没有人工作。请帮忙。提前致谢。
喔感谢。我已经用相同的解决方案解决了这个问题。 –
你能告诉我一件事...我想在应用程序页面上张贴图像。怎么能做到这一点。任何线索。谢谢 –
对不起,从来没有做过这样的事情:( – KIDdAe