get Facebook user profile data after getting access token in iOS 5

后端 未结 3 1462
有刺的猬
有刺的猬 2020-12-21 15:12

I am working on an iOS 5 app where i need to get user profile data after successful login.

For now I am getting a access token when user get successful login.

<
3条回答
  •  北海茫月
    2020-12-21 15:30

    This is the method to get user profile picture:

    //in your app delegate file configure "FBProfilePictureView" class
    - (void)applicationDidFinishLaunching:(UIApplication *)application {    
        [FBProfilePictureView class];
    }
    
    //in your header file
    IBOutlet FBProfilePictureView   *userPictureView;
    
    
    @property (strong, nonatomic) FBProfilePictureView     *userPictureView;
    
    //here "userPictureView" is uiview not uiimageview
    
    //in your .m file 
    
    -(void)setProfilePicture {
        [FBSession.activeSession closeAndClearTokenInformation];
    
        NSArray *permissions = [NSArray arrayWithObjects:@"email", nil];
    
        [FBSession openActiveSessionWithReadPermissions:permissions
                                           allowLoginUI:YES
                                      completionHandler:
         ^(FBSession *session,
           FBSessionState state, NSError *error) {
             NSLog(@"\nfb sdk error = %@", error);
             switch (state) {
                 case FBSessionStateOpen:
                     [[FBRequest requestForMe] startWithCompletionHandler:
                      ^(FBRequestConnection *connection, NSDictionary *user, NSError *error) {
                          if (!error) {
    
                              self.userPictureView.profileID = [user objectForKey:@"id"];
    
                          } 
                      }];
                     break;
                 case FBSessionStateClosed:
                     //need to handle
                     break;
                 case FBSessionStateClosedLoginFailed:
                     //need to handle
                     break;
                 default:
                     break;
             }
         }];
    }
    

提交回复
热议问题