2

Facebook をアプリに統合しようとしています。ユーザーの誕生日、名前、メールアドレスが必要です。

SDKから統合しFacebookloginviewました。

ログインをクリックすると、アプリが Safari に切り替わり、ページにアプリが既に承認されていることが表示されます。でもメールも誕生日も届かない

のようにアクセス許可を変更user_locationし、ログアウトしてアプリにログインすると、既に承認されていることが示されますが、そうではありません!

xib にボタンを実装してから ibaction に追加すると、このコードが機能します。

AppDelegate *appDelegate    [[UIApplication sharedApplication] delegate];

// If the person is authenticated, log out when the button is clicked.
// If the person is not authenticated, log in when the button is clicked.
if (FBSession.activeSession.isOpen) {
    [appDelegate closeSession];
} else {
    // The person has initiated a login, so call the openSession method
    // and show the login UX if necessary.
    [appDelegate openSessionWithAllowLoginUI:YES];
}


}

facebookloginview で機能しないのはなぜですか?

これが私のFacebook loginviewcontroller.mです

- (void)viewDidLoad
{
[super viewDidLoad];
loginview = [[FBLoginView alloc]init];
loginview.readPermissions = @[@"email"];
//Facebook start
[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(sessionStateChanged:)
 name:FBSessionStateChangedNotification
 object:nil];
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate openSessionWithAllowLoginUI:NO];
if (!appDelegate.session.isOpen) {
    // create a fresh session object
    appDelegate.session = [[FBSession alloc] init];
    // if we don't have a cached token, a call to open here would cause UX for login to
    // occur; we don't want that to happen unless the user clicks the login button, and so
    // we check here to make sure we have a token before calling open
    if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
        // even though we had a cached token, we need to login to make the session usable
        [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                         FBSessionState status,
                                                         NSError *error) {
            // we recurse here, in order to update buttons and labels
            [self updateView];
        }];
    }
}
}
-(void) loginViewShowingLoggedOutUser:(FBLoginView *)loginView{
self.loginlabel.text = @"";
self.FBimageViewOutlet.profileID = nil;
NSLog(@"bin hier geklickt3");    
}
-(void) loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user{
loginView.readPermissions = @[@"email"];
 FBRequest *me = [FBRequest requestForMe];
[me startWithCompletionHandler: ^(FBRequestConnection *connection,
                                  NSDictionary<FBGraphUser> *my,
                                  NSError *error) {
    self.loginlabel.text = [NSString stringWithFormat:@"Hi, %@ %@ geboren am %@",my.first_name,my.last_name,my.birthday];
    self.FBimageViewOutlet.profileID = my.id;
    self.picView.profileID =my.id;}];

//self.loginlabel.text = [NSString stringWithFormat:@"Hi, %@ %@ geboren am %@",user.first_name,user.last_name,user.birthday];
self.FBimageViewOutlet.profileID = user.id;
//Hier wird gender von Facebook abgefragt
NSLog(@"%@",[user objectForKey:@"gender"]);
NSLog(@"%@",[user objectForKey:@"locale"]);
NSLog(@"%@",[user objectForKey:@"age_range"]);
NSLog(@"%@",[user objectForKey:@"username"]);
NSLog(@"%@",[user objectForKey:@"link"]);
NSLog(@"%@",[user objectForKey:@"location"]);
NSLog(@"%@",[user objectForKey:@"hometown"]);
NSLog(@"%@",[user objectForKey:@"birthday"]);
NSLog(@"%@",[user objectForKey:@"last_name"]);
NSLog(@"%@",[user objectForKey:@"first_name"]);
NSLog(@"%@",[user objectForKey:@"email"]);
NSLog(@"%@",[user objectForKey:@"user_email"]);
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
[defaults setObject:[user objectForKey:@"gender"] forKey:@"user_gender"];
[defaults setObject:[user objectForKey:@"locale"] forKey:@"user_locale"];
[defaults setObject:[user objectForKey:@"age_range"] forKey:@"user_age_range"];
[defaults setObject:[user objectForKey:@"username"] forKey:@"user_username"];
[defaults setObject:[user objectForKey:@"link"] forKey:@"user_link"];
[defaults setObject:[user objectForKey:@"location"] forKey:@"user_location"];
[defaults setObject:[user objectForKey:@"hometown"] forKey:@"user_hometown"];
[defaults setObject:[user objectForKey:@"birthday"] forKey:@"user_birthday"];
[defaults setObject:[user objectForKey:@"last_name"] forKey:@"user_lastname"];
[defaults setObject:[user objectForKey:@"first_name"] forKey:@"user_firstname"];
}
- (void)loginView:(FBLoginView *)loginView
  handleError:(NSError *)error {
AppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
// If the person is authenticated, log out when the button is clicked.
// If the person is not authenticated, log in when the button is clicked.
if (FBSession.activeSession.isOpen) {
    [appDelegate closeSession];
} else {
    // The person has initiated a login, so call the openSession method
    // and show the login UX if necessary.
    [appDelegate openSessionWithAllowLoginUI:YES];
}
NSString *alertMessage, *alertTitle;
if (error.fberrorShouldNotifyUser) {
    // If the SDK has a message for the user, surface it. This conveniently
    // handles cases like password change or iOS6 app slider state.
    alertTitle = @"Facebook Error";
    alertMessage = error.fberrorUserMessage;
} else if (error.fberrorCategory == FBErrorCategoryAuthenticationReopenSession) {
    // It is important to handle session closures since they can happen
    // outside of the app. You can inspect the error for more context
    // but this sample generically notifies the user.
    alertTitle = @"Session Error";
    alertMessage = @"Your current session is no longer valid. Please log in again.";
} else if (error.fberrorCategory == FBErrorCategoryUserCancelled) {
    // The user has cancelled a login. You can inspect the error
    // for more context. For this sample, we will simply ignore it.
    NSLog(@"user cancelled login");
} else {
    // For simplicity, this sample treats other errors blindly.
    alertTitle  = @"Unknown Error";
    alertMessage = @"Error. Please try again later.";
    NSLog(@"Unexpected error:%@", error);
}
if (alertMessage) {
    [[[UIAlertView alloc] initWithTitle:alertTitle
                                message:alertMessage
                               delegate:nil
                      cancelButtonTitle:@"OK"
                      otherButtonTitles:nil] show];
}
}
4

0 に答える 0