gpt4 book ai didi

ios - 使用 Parse API 将用户名设置为 Facebook 名称。

转载 作者:行者123 更新时间:2023-11-29 12:46:03 25 4
gpt4 key购买 nike

目前这是我的 LogInViewController 中的代码,其中包含 Facebook 注册过程的处理程序和我希望将用户名和电子邮件地址设置为他们的 Facebook 名称和电子邮件地址的代码。

- (IBAction)fbButtonPressed:(id)sender
{
NSArray *permissions =@[@"public_profile", @"email", @"user_friends"];

[PFFacebookUtils logInWithPermissions:permissions block:^(PFUser *user, NSError *error) {
if (!user) {
NSLog(@"Uh oh. The user cancelled the Facebook login.");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Log In Error" message:@"Uh oh. The user cancelled the Facebook login." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Dismiss", nil];
[alert show];
} else if (user.isNew) {
NSLog(@"User signed up and logged in through Facebook!");
FBRequest *request = [FBRequest requestForMe];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error){
NSDictionary *userData = (NSDictionary *)result;

NSString *facebookID= userData[@"ID"];

NSURL *pictureURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1", facebookID]];


NSMutableDictionary *userProfile = [NSMutableDictionary dictionaryWithCapacity:7];

if (facebookID){
userProfile[@"facebookID"] = facebookID;
}

if (userData[@"name"]) {

user.username = userProfile[@"name"];
}

if (userData[@"email"]){
user.email = userData[@"emai"];
}


[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error){
NSLog(@"ERROR: %@ %@", error, [error userInfo]);

}else{
[self.navigationController popToRootViewControllerAnimated:YES];
}
}];



}
}];


} else {
NSLog(@"User logged in through Facebook!");
[self.navigationController popToRootViewControllerAnimated:YES];
}
}];
}

最佳答案

输入错误

user.email = userData[@"emai"];

此外,对于名称,您尝试从 userProfile 中获取名称:

if (userData[@"name"]) {
user.username = userProfile[@"name"];
}

应该是

if (userData[@"name"]) {
user.username = userData[@"name"];
}

关于ios - 使用 Parse API 将用户名设置为 Facebook 名称。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23669300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com