Search code examples
iosobjective-cfacebookfbconnectposting

session.state FBSessionStateCreated is not posting on fb wall in ios


I am facing an issue. when i logged in Facebook account in my application. At the time of 1st posting i am getting this this FBSession response it working fine and posting on FBWall normaly.

FBSESSION <FBSession: 0x1c31bbc0, state: FBSessionStateCreatedTokenLoaded, loginHandler: 0x0, appID: 524460600950223, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x176c99b0>, expirationDate: 2015-02-27 10:42:15 +0000, refreshDate: 2014-12-30 06:24:28 +0000, attemptedRefreshDate: 0000-12-30 00:00:00 +0000, permissions:(
"create_note",
"basic_info",
"share_item",
"read_stream",
"status_update",
"publish_actions",
"user_friends",
"publish_checkins",
"video_upload",
"export_stream",
"publish_stream",
"photo_upload",
installed,
email,
"public_profile",
"user_birthday",
"user_status"
)>

from 2nd time onwards i am trying to post i am getting the FBSession like this shown in below it will not posting on FBWall

FBSESSION <FBSession: 0x1d05fac0, state: FBSessionStateCreated, loginHandler: 0x0, appID: 524460600950223, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x176c99b0>, expirationDate: (null), refreshDate: (null), attemptedRefreshDate: 0000-12-30 00:00:00 +0000, permissions:(null)>

//This will happens at the time of Loginwithfacebook account... otherwise it will work fine  
//can any one help me. Thanks in advance

Solution

  • I got the sollution. No need to check the session if we are logged in with facebook account.. Just post what u want

    FBSession *session = [[FBSession alloc] init];
    
    NSLog(@"FBSESSION %@", session);
    
    if (session.state == FBSessionStateCreatedTokenLoaded || session.state == FBSessionStateOpen )
    {
    
        [[[[iToast makeText:@"Post on wall success"] setGravity:iToastGravityBottom] setDuration:iToastDurationShort]show];
        // even though we had a cached token, we need to login to make the session usable
        [session openWithCompletionHandler:^(FBSession *session,
                                             FBSessionState status,
                                             NSError *error) {
            [FBSession setActiveSession:session];
            [FBRequestConnection startWithGraphPath:@"/me/feed"
                                         parameters:params
                                         HTTPMethod:@"POST"
                                  completionHandler:^(FBRequestConnection *connection, id result, NSError *error){
                                      NSLog(@"error-- %@",error);
                                  }];
        }];
    }
    

    Previously my code is like this shown in the above

    I just added else part to the above code it will work correctly.My issue will resolved.

    else
    {
    
    [[[[iToast makeText:@"Post on wall success"] setGravity:iToastGravityBottom] setDuration:iToastDurationShort]show];
    [FBRequestConnection startWithGraphPath:@"/me/feed"
                                 parameters:params
                                 HTTPMethod:@"POST"
                          completionHandler:^(FBRequestConnection *connection, id result, NSError *error){
                              NSLog(@"error-- %@",error);
                          }];
    }