2

サーバーからFacebookトークンをフェッチしています(別のデバイスでの以前のログインから保存された場所)。私はそれを使用してセッションを開き、次に比較的単純な呼び出しを行っています

[FBWebDialogs presentRequestsDialogModallyWithSession:[FBSession activeSession]
                                                  message:@"Message"
                                                    title:@"Title"
                                               parameters:params
                                                  handler:^(FBWebDialogResult result,
                                                  NSURL *resultURL, NSError *error) {}}];

ポップアップする Web ウィンドウには、「エラーが発生しました。後でもう一度やり直してください。」というメッセージが表示されます。[OK] をクリックして、コールバックをトリガーします (上記では省略しました)。resultURL をトレースすると、

fbconnect://success?error_code=110&error_msg=Missing+user+cookie+%28to+validate+session+user%29

セッションを使用して、自分の壁に問題なく投稿できます。私は何が欠けていますか?

4

3 に答える 3

0

アクティブな Facebook セッションで「publish_actions」権限があることを確認してください。

    bool hasPublishPermission = NO;
    for( NSString* permission in [FBSession.activeSession permissions] )
    {
        if( [permission isEqualToString:@"publish_actions"] )
        {
            hasPublishPermission = YES;
            break;
        }
    }
    if( !hasPublishPermission )
    {
        [FBSession openActiveSessionWithPublishPermissions:@[@"publish_actions"]
                                           defaultAudience:FBSessionDefaultAudienceFriends
                                              allowLoginUI:YES
                                         completionHandler:^(FBSession *session,
                                                             FBSessionState status,
                                                             NSError *error) {
                                             if( status==FBSessionStateOpen )
                                             {
                                                 //Present dialog
                                             }
                                         }];
    }
    else
    {
        //Present dialog
    }

また、プロジェクトの plist に「FacebookAppID」を追加したことを確認してください。( https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/の「Configure a new Xcode Project」タブを参照してください) これにより、説明しているエラーが発生する可能性があります。

お役に立てれば

于 2013-07-31T14:17:24.080 に答える
0

Facebook SDK 3.5.3 を使用してアプリに埋め込み Web ビューを統合 しました

私のコードがあなたに何らかのアイデアを与えることを願っています...

-(IBAction)fblogin:(id)sender{
         NSArray * arr=[NSArray                arrayWithObjects:@"publish_actions",@"email",@"basic_info",@"user_location",@"user_birthday",@"user_likes", nil];

        Interest_Status=[NSString stringWithFormat:@"%@",txt_interest.text];
            [FBSession  setActiveSession:session];

        if (FBSession.activeSession.isOpen) {
            if ([btn_Login.titleLabel.text isEqualToString:@"Logout"]) {

                [btn_Login setTitle:@"Login" forState:UIControlStateNormal];
                [btn_Login setImage:[UIImage imageNamed:@"FBLogin.png"] forState:UIControlStateNormal];


                FBSessionTokenCachingStrategy *tokenCachingStrategy = [[FBSessionTokenCachingStrategy alloc]
                                                                       initWithUserDefaultTokenInformationKeyName:nil];

                tokenCachingStrategy=nil;
                FBSession *seession=[FBSession activeSession];
                [seession closeAndClearTokenInformation];
                [session close];
                [FBSession setActiveSession:nil];
                session=nil;

                session=[[FBSession alloc]initWithPermissions:arr];
                self.ProfileLale.hidden=YES;


            }
            /*else if ([btn_Login.titleLabel.text isEqualToString:@"Login"]) {
                    [self updateForSessionChangeForSlot:1];
            }*/


        }else{
            [session openWithBehavior:FBSessionLoginBehaviorForcingWebView
                    completionHandler:^(FBSession *session,
                                        FBSessionState status,
                                        NSError *error) {
                            // this handler is called back whether the login succeeds or fails; in the
                            // success case it will also be called back upon each state transition between
                            // session-open and session-close
                        if (error)
                                {
                                    NSLog(@"error=%@ \n\n description=%@ \n\n,",error,error.description);
                                    [self switchToNoActiveUser];
                                }else{
                                    [self updateForSessionChangeForSlot:1];
                                }
                    }];

        }
 }




- (void)updateForSessionChangeForSlot:(int)slot {
   if (session.isOpen) {
                // fetch profile info such as name, id, etc. for the open session
                // Fetch user data
            FBRequest *me = [[FBRequest alloc] initWithSession:session
                                                     graphPath:@"me"];

            [me startWithCompletionHandler:^(FBRequestConnection *connection,
                                             NSDictionary<FBGraphUser> *user,
                                             NSError *error) {
                    // because we have a cached copy of the connection, we can check
                    // to see if this is the connection we care about; a prematurely
                    // cancelled connection will short-circuit here
                    //   if (me != self.pendingRequest) {
                    //      return;
                    //  }
                  NSLog(@"user=%@",user);

                    //  self.pendingRequest = nil;
                    //  self.pendingLoginForSlot = -1;

                    // we interpret an error in the initial fetch as a reason to
                    // fail the user switch, and leave the application without an
                    // active user (similar to initial state)
                if (error) {
                    NSLog(@"error=%@",error);
                    NSLog(@"Couldn't switch user: %@", error.localizedDescription);
                    [self switchToNoActiveUser];
                    return;
                }else{
                     NSLog(@"user=%@",user);
                     [btn_Login setTitle:@"Logout" forState:UIControlStateNormal];
                     [btn_Login setImage:[UIImage imageNamed:@"FBLogout.png"] forState:UIControlStateNormal];

                }
            }];

        } else {
                // in the closed case, we check to see if we picked up a cached token that we
                // expect to be valid and ready for use; if so then we open the session on the spot
            if (session.state == FBSessionStateCreatedTokenLoaded) {
                    // even though we had a cached token, we need to login to make the session usable
                [session openWithCompletionHandler:^(FBSession *session,
                                                     FBSessionState status,
                                                     NSError *error) {
                    [self updateForSessionChangeForSlot:slot];
                }];
            }
        }

  }



- (void)switchToNoActiveUser {

      /*UIAlertView *alter=[[UIAlertView alloc]initWithTitle:@"Message" message:@"No Internet connecton" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alter show];
       */
         NSArray * arr=[NSArray             arrayWithObjects:@"publish_actions",@"email",@"basic_info",@"user_location",@"user_birthday",@"user_likes", nil];

        session = nil;
        session=[[FBSession alloc]initWithPermissions:arr];
        [btn_Login setTitle:@"Login" forState:UIControlStateNormal];
        self.ProfileLale.hidden=YES;
        [btn_Login setImage:[UIImage imageNamed:@"FBLogin.png"] forState:UIControlStateNormal];

    }
于 2013-08-01T11:49:54.973 に答える