Ios Facebook信息未填充解析数据库
当用户在我的应用程序中通过facebook登录时,我会查询他们的图片和姓名,并使用这些信息填充核心数据和我的Parse.com后端。但是,它不起作用。以下是执行所有操作的代码:Ios Facebook信息未填充解析数据库,ios,objective-c,core-data,parse-platform,facebook-sdk-3.0,Ios,Objective C,Core Data,Parse Platform,Facebook Sdk 3.0,当用户在我的应用程序中通过facebook登录时,我会查询他们的图片和姓名,并使用这些信息填充核心数据和我的Parse.com后端。但是,它不起作用。以下是执行所有操作的代码: #pragma mark - () - (IBAction)authButtonAction:(id)sender { AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; // If the person i
#pragma mark - ()
- (IBAction)authButtonAction:(id)sender {
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];
self.authButton.hidden = YES;
}
}
- (IBAction)toQuadAction:(id)sender {
// Query to fetch the users name and picture
NSString *query = @"SELECT name, username FROM user WHERE uid=me() ";
// Set up the query parameter
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]);
} else {
NSLog(@"My name: %@", result[@"data"][0][@"name"]);
NSLog(@"My username: %@", result[@"data"][0][@"username"]);
//SAVE TO CORE DATA
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSEntityDescription *user = [NSEntityDescription entityForName:@"User" inManagedObjectContext:appDelegate.managedObjectContext];
NSFetchRequest *getName = [[NSFetchRequest alloc] init];
[getName setReturnsObjectsAsFaults:NO];
[getName setEntity:user];
NSError *error;
NSMutableArray *currentUser = [[appDelegate.managedObjectContext executeFetchRequest:getName error:&error] mutableCopy];
//SAVE THE NAME TO CORE DATA
[currentUser[0] setName:result[@"data"][0][@"name"]];
//SAVE NAME AND PICTURE TO PARSE
PFQuery *query = [PFQuery queryWithClassName:@"Student"];
[query whereKey:@"email" equalTo:[currentUser[0] valueForKey:@"email"]];
[query getFirstObjectInBackgroundWithBlock:^(PFObject *users, NSError *error) {
if (!users){
NSLog(@"The first object request failed");
} else{
NSLog(@"grabbed the object");
//SET THE NAME IN PARSE
[users setObject:result[@"data"][0][@"name"] forKey:@"name"];
//SET THE IMAGE IN PARSE
NSString *URLString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?width=235&height=385", result[@"data"][0][@"username"]];
NSURL *picURL = [NSURL URLWithString:URLString];
NSData *picData = [NSData dataWithContentsOfURL:picURL];
PFFile *picture = [PFFile fileWithData:picData ];
[users setObject:picture forKey:@"picture"];
[users saveInBackground];
}
}];
}
[self performSegueWithIdentifier:@"facebookToQuad" sender:sender];
}];
}
所以,这里有一个auth按钮。用户点击该按钮并登录Facebook。然后另一个按钮出现,允许他们进入应用程序。当他们点击该按钮时,我们会查询他们的facebook个人资料中的图片和姓名,并添加核心数据,然后进行解析。但是,目前,这两个存储系统都没有被填充 使用更多的空白,并声明更多的实例变量。打开你的代码,这样你就能更容易地发现你的问题 例如,拉出
result[@“data”][0][@“name”]
并将其分配给它自己的局部变量
在CoreData中对实体进行子类化,以便更容易使用setter和getter管理属性分配
然后设置断点并检查代码的每个步骤