Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
FBSession:尝试在ios中对未打开的会话重新授权权限_Ios_Facebook - Fatal编程技术网

FBSession:尝试在ios中对未打开的会话重新授权权限

FBSession:尝试在ios中对未打开的会话重新授权权限,ios,facebook,Ios,Facebook,大家好,我正在我的项目中使用facebook SDK 3.8。在我的应用程序中使用HelloFaceBook示例代码,但在我的应用程序中,我没有facebook的登录按钮。我已经实现了facebook的登录流,登录后我在facebook上发布了帖子。现在发布状态很好,但当我在facebook上发布图像时,它会给我错误信息 an attempt was made reauthorize permissions on an unopened session in ios 代码: -(void) c

大家好,我正在我的项目中使用facebook SDK 3.8。在我的应用程序中使用HelloFaceBook示例代码,但在我的应用程序中,我没有facebook的登录按钮。我已经实现了facebook的登录流,登录后我在facebook上发布了帖子。现在发布状态很好,但当我在facebook上发布图像时,它会给我错误信息

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方法中的错误


谁能告诉我出了什么问题。我进行了大量搜索,也找到了许多解决方案,但没有一个可行。请帮忙。提前感谢。

我认为您必须将其活动会话设置为FBSession:

FBSession *session = [[FBSession alloc] init];
[FBSession setActiveSession:session];

哦,谢谢。我已经用同样的方法解决了这个问题。你能告诉我一件事吗…我想在应用程序页面上发布图片。如何才能做到这一点。任何线索。thanks@KIdAe .. 什么是不应该做的?