【问题标题】:Facebook is not returning me the parameters what I askFacebook 没有返回我所要求的参数
【发布时间】:2017-08-07 18:15:31
【问题描述】:

您好,至少对我来说,我正在处理一个大问题,我已经实现了旧版本的 Facebook SDK 我在我的应用中使用这个 SDK 有很多功能,更新到最新版本需要几天时间,我现在没有时间这样做,所以我想做的很简单,我只想接收参数 email、last_name 和 name 但 Facebook 只是返回我的名字和 id,所以你有什么想法或我做错了什么?提前致谢。

- (void)requestUserInfo{
    // We will request the user's public picture and the user's birthday
    // These are the permissions we need:
    NSArray *permissionsNeeded = @[@"public_profile", @"email"];
    // Request the permissions the user currently has
    if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded)
    {
        // If there's one, just open the session silently, without showing the user the login UI
        [FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"email"]
                                           allowLoginUI:NO
                                      completionHandler:^(FBSession *session,     FBSessionState state, NSError *error)
         {
             NSLog(@"%@", session.accessTokenData.accessToken);
         }];
    }

    [FBRequestConnection startWithGraphPath:@"me"
                                 parameters:[NSDictionary dictionaryWithObject:@"id,email,name,last_name" forKey:@"fields"]
                                 HTTPMethod:@"GET"
                          completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                              if (!error){

                                  // Parse the list of existing permissions and extract them for easier use
                                  NSMutableArray *currentPermissions = [[NSMutableArray alloc] init];
                                  NSArray *returnedPermissions = (NSArray *)[result data];
                                  for (NSDictionary *perm in returnedPermissions) {
                                      if ([[perm objectForKey:@"status"] isEqualToString:@"granted"]) {
                                          [currentPermissions addObject:[perm objectForKey:@"permission"]];
                                      }
                                  }

                                  //NSLog(@"Needed: %@", permissionsNeeded);
                                  //NSLog(@"Current: %@", currentPermissions);

                                  NSMutableArray *requestPermissions = [[NSMutableArray alloc] initWithArray:permissionsNeeded copyItems:YES];
                                  [requestPermissions removeObjectsInArray:currentPermissions];

                                  //NSLog(@"Asking: %@", requestPermissions);

                                  // If we have permissions to request
                                  if ([requestPermissions count] > 0){
                                      // Ask for the missing permissions
                                      [FBSession.activeSession
                                       requestNewReadPermissions:requestPermissions
                                       completionHandler:^(FBSession *session, NSError *error) {
                                           if (!error) {
                                               // Permission granted, we can request the user information
                                               [self makeRequestForUserData];
                                           } else {
                                               // An error occurred, we need to handle the error
                                               // Check out our error handling guide: https://developers.facebook.com/docs/ios/errors/
                                               NSLog(@"error %@", error.description);
                                           }
                                       }];
                                  } else {
                                      // Permissions are present
                                      // We can request the user information
                                      [self makeRequestForUserData];

                                  }

                              } else {
                                  // An error occurred, we need to handle the error
                                  // Check out our error handling guide: https://developers.facebook.com/docs/ios/errors/
                                  NSLog(@"error %@", error.description);
                              }
                          }];



}

这是信息:

 llega el objeto:{
    id = 10210924411602727;
    name = "Del Mar Sal";
}

【问题讨论】:

    标签: ios objective-c facebook


    【解决方案1】:

    下面我附上了 Facebook 的 FB 登录和获取详细信息。试试这个代码并比较。

    - (IBAction)facebook_BtnTap:(id)sender {
    
    
        FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    
    
      [login logInWithReadPermissions:@[@"public_profile",@"email"]handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
         {
    
             if (error) {
    
                 NSLog(@"Process error");
    
    
    
             } else if (result.isCancelled) {
                 NSLog(@"Cancelled");
    
             } else {
    
                 if ([result.grantedPermissions containsObject:@"email"]) {
                     // Do work
                     [self GetUserDetails];
    
                 }
             }
         }];
    }
    
    
    -(void)GetUserDetails
    {
        BOOL LOGGING;
    
        if (LOGGING) {
            return;
        }
        LOGGING = YES;
        //    [super startLoader];
    
        if ([FBSDKAccessToken currentAccessToken])
        {
            NSLog(@“Check Already login");
            //[FBSession openActiveSessionWithAllowLoginUI: YES];
    
            // [self back:nil];
    
            // return;
        }
    
        NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
        [parameters setValue:@"id,name,email,first_name,last_name,birthday,picture.type(large),location,hometown,gender" forKey:@"fields"];
    
    
        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error) {
    
    
                 NSString* email = [result objectForKey:@"email"];
                 NSString* fname = [result objectForKey:@"first_name"];
                 NSString* lname = [result objectForKey:@"last_name"];
    
                 NSString* userName = [result objectForKey:@"name"];
                 NSString* gender = [result objectForKey:@"gender"];
    
                 NSDictionary* hometown=[result objectForKey:@"hometown"];
                 NSString* country = [hometown objectForKey:@"name"];
    
                 NSString* birthday=[result objectForKey:@"birthday"];
    
                 //   NSArray* photo =[[result objectForKey:@"picture"]valueForKey:@"data"];
                 //       NSDictionary* location = [result objectForKey:@"location"];
    
                 //   NSString* city = [location valueForKey:@"name"];
    
                 //    NSString*  fbPhoto = [photo valueForKey:@"url"];
    
    
                 NSString*   fid = [result objectForKey:@"id"];
    
    
         }];
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-20
      • 2011-04-06
      • 1970-01-01
      • 2011-12-01
      • 2021-06-27
      • 1970-01-01
      • 2018-12-09
      • 1970-01-01
      相关资源
      最近更新 更多