session.state FBSessionStateCreated未在ios中的fb wall上发布

时间:2014-12-30 07:05:01

标签: ios objective-c facebook fbconnect posting

我正面临一个问题。当我在我的应用程序中登录Facebook帐户时。在第一次发布时,我得到了这个FBSession响应它工作正常并在FBWall上发布正常。

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"
)>

从第2次开始我试图发布我正在获得如下所示的FBSession它将不会在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

2 个答案:

答案 0 :(得分:0)

我得到了溶剂。如果我们使用Facebook帐户登录,则无需检查会话。只需发布您想要的内容

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);
                              }];
    }];
}

以前我的代码如上所示

我刚刚在上面的代码中添加了其他部分,它将正常工作。我的问题将得到解决。

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);
                      }];
}

答案 1 :(得分:0)

您的代码中的以下行需要修改:

if (session.state == FBSessionStateCreatedTokenLoaded || session.state == FBSessionStateOpen )

if (session.state == FBSessionStateCreatedTokenLoaded || session.state == FBSessionStateCreated )

如果会话状态已经打开,则无需再次打开FBSession。

如果会话已创建或加载了令牌,则您需要再次打开会话。