Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.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
Iphone ios应用程序中的FB集成问题_Iphone_Ios_Facebook_Facebook Graph Api_Facebook Fql - Fatal编程技术网

Iphone ios应用程序中的FB集成问题

Iphone ios应用程序中的FB集成问题,iphone,ios,facebook,facebook-graph-api,facebook-fql,Iphone,Ios,Facebook,Facebook Graph Api,Facebook Fql,我已经在我的ios应用程序中集成了facebook,它运行得很好。 但当我在设置中存储我的FB凭据时,它不起作用。 它处于以下状态 - (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error { switch (state) { case

我已经在我的ios应用程序中集成了facebook,它运行得很好。 但当我在设置中存储我的FB凭据时,它不起作用。 它处于以下状态

    - (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState) state
                      error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen:
            NSLog(@"case open session");
            // if([sharePref returnFbName].length==0)
            [self listFriendsFB];
            break;
        case FBSessionStateClosed:
            NSLog(@"case FBSessionStateClosed session");
        case FBSessionStateClosedLoginFailed:
            // Once the user has logged in, we want them to
            // be looking at the root view.
            //[viewController popToRootViewControllerAnimated:NO];
            [FBSession.activeSession closeAndClearTokenInformation];
            NSLog(@"case close or fail session");
            break;
        default:
            break;
    }
它进入FBSessionStateClosedLoginFailed,并发生错误。 如果我从手机设置中删除我的帐户,它将正常工作,即会话将打开并正确登录。 这是我的密码

- (void)openSession
{
    //[self syncFacebookAccount];
    NSArray *permissions=[[NSArray alloc]initWithObjects:@"email,publish_actions",nil];
    dispatch_async(dispatch_get_main_queue(), ^{

    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session,
       FBSessionState state, NSError *error) {
         NSLog(@"fb open session");
         [self sessionStateChanged:session state:state error:error];
     }];
    });

}

- (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState) state
                      error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen:
            NSLog(@"case open session");
            // if([sharePref returnFbName].length==0)
            [self fourthViewInitialization];
            [self getFacebookInfo];
            break;
        case FBSessionStateClosed:
            NSLog(@"case FBSessionStateClosed session");
        case FBSessionStateClosedLoginFailed:
            // Once the user has logged in, we want them to
            // be looking at the root view.
            //[viewController popToRootViewControllerAnimated:NO];
            [FBSession.activeSession closeAndClearTokenInformation];
            NSLog(@"case close or fail session");

            break;
        default:
            break;
    }

    if (error) {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:AlertTitle
                                  message:@"We are currently facing facebook connectivity issues. Please try again later!"
                                  delegate:nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        NSLog(@"error facebook : %@",error);
        [alertView show];
        [self hideActivityIndicator];
    }
}


#pragma facebook methods
-(void)getFacebookInfo
{
    //    [NSThread detachNewThreadSelector:@selector(startLoader) toTarget:self withObject:nil];
    NSString *query =[NSString stringWithFormat:@"Select name,uid,pic_square from user where uid=me()"];
    // Set up the query parameter
    my_info=[[NSMutableDictionary alloc]init];
    my_info_array=[[NSMutableArray alloc ]init];
    NSDictionary *queryParam =
    [NSDictionary dictionaryWithObjectsAndKeys:query, @"q", nil];
    // Make the API request that uses FQL
    [FBRequestConnection startWithGraphPath:@"/fql"
                                 parameters:queryParam
                                 HTTPMethod:@"GET"
                          completionHandler:^(FBRequestConnection *connection,
                                              id result,
                                              NSError *error) {
                              if (error) {
                                  NSLog(@"Error: %@", [error localizedDescription]);
                                  [self hideActivityIndicator];
                              } else {
                                  // NSLog(@"Result: %@", result);
                                  //   [self hideActivityIndicator];


                                  my_info_array=(NSMutableArray *)[result objectForKey:@"data"];
                                  my_info=[my_info_array objectAtIndex:0];
                                  //NSLog(@"my info array %@",my_info_array);
                                  NSLog(@"my info from fb %@",my_info);
                                  //return my_info;
                                  [firstView removeFromSuperview];
                                  [self.view addSubview:fourthView];
                                  displayNameLabel.text=[NSString stringWithFormat:@"%@%@",displayNameLabel.text,[my_info objectForKey:@"name"]];
                                  [registerRequest setObject:[my_info objectForKey:@"name"] forKey:@"displayName"];
                                  //[registerRequest setObject:[my_info objectForKey:@"email"] forKey:@"emailId"];
                                  [registerRequest setObject:[my_info objectForKey:@"uid"] forKey:@"uid"];

                                  [SharedPreferenceClass setFBUID:[my_info objectForKey:@"uid"]];// 30 sept

                                  [registerRequest setObject:[my_info objectForKey:@"pic_square"] forKey:@"profilePic"];
                                  NSString* picPath = [my_info objectForKey:@"pic_square"];
                                  if (picPath.length>0) {
                                       [SharedPreferenceClass setUserProfilePictureDefault:picPath];
                                  }else{
                                      [SharedPreferenceClass setUserProfilePictureDefault:@""];
                                  }

                                  //displayName.text=[my_info objectForKey:@"name"];
                                  [self hideActivityIndicator];
                              }
                          }];
}

提前感谢。

当FB凭据在电话设置中可用时,我使用此选项打开会话

 // Initialize a session object
    FBSession *session = [[FBSession alloc] init];
    // Set the active session
    [FBSession setActiveSession:session];

    [session openWithBehavior:FBSessionLoginBehaviorWithFallbackToWebView
            completionHandler:^(FBSession *session,
                                FBSessionState status,
                                NSError *error) {
                // Respond to session state changes,
                NSLog(@"fb open session %@",error);
                [self sessionStateChanged:session state:status error:error];
            }];
一旦会话打开,我就使用以下代码来获取FB friends数据

 NSArray *permissions=[[NSArray alloc]initWithObjects:@"email,publish_actions",nil];
    dispatch_async(dispatch_get_main_queue(), ^{

    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session,
       FBSessionState state, NSError *error) {
         NSLog(@"fb open session");
         [self sessionStateChanged:session state:state error:error];
     }];
    });

谢谢你的回复,但它对我不起作用!您是否尝试过包含此方法-(BOOL)应用程序:(UIApplication*)应用程序openURL:(NSURL*)url源应用程序:(NSString*)源应用程序注释:(id)注释