0
- (IBAction)loginbtnclicked:(id)sender
{
if (!FBSession.activeSession.isOpen)
{
[FBSession.activeSession openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error)
{
if (error)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
else if(session.isOpen)
{
[FBSession openActiveSessionWithReadPermissions:@[@"email",@"user_location",@"user_birthday",@"user_hometown"]
allowLoginUI:NO
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (error)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
else if(session.isOpen)
{
[FBSession setActiveSession:session];
[self loginbtnclicked:sender];
}
}];
}
}];
return;
}
[FBRequestConnection startWithGraphPath:@"me" parameters:[NSDictionary dictionaryWithObject:@"picture,id,birthday,email,name,gender,hometown,about" forKey:@"fields"] HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (!error)
{
if ([result isKindOfClass:[NSDictionary class]])
{
if([result objectForKey:@"data"])
dictionary = (NSDictionary *)[(NSArray *)[result objectForKey:@"data"] objectAtIndex:0];
else
dictionary = (NSDictionary *)result;
user_email = [dictionary objectForKey:@"email"];
[dictionary retain];
accessTokan = [[[FBSession activeSession] accessTokenData] accessToken];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@",accessTokan]]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
fb_dict = [str JSONValue];
[str release];
NSLog(@"fb dict %@",fb_dict);
[fb_dict retain];
[self getfriends];
}
}
}];
}
}如何獲取關於Facebook的用戶和家鄉使用AccountIfPresent在IOS SDK
我已經採取了所有許可 –
檢查我的更新答案 – Vizllx
但是當我用這個fBSessionLoginBehaviorUseSystemAccountIfPresent則無法獲得有關和家鄉 –