这是我的代码,我只获取用户名和用户的Facebook ID。
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: @[@"public_profile",@"email",@"user_friends"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
}
}];
} NSLog(@"Results=%@",result);
NSLog(@"Logged in");
}
}];
它也会出现这样的错误 -
-canOpenURL:网址失败:" fbauth2:/" - 错误:"(null)" -canOpenURL:URL失败:" fbauth2:/" - 错误:"(null)"
FBSDKLog:从Graph API v2.4开始,对/ me的GET请求应该 包含一个明确的"字段"参数
答案 0 :(得分:6)
我正在使用pod for Facebook sdk,它在iOS9.0中使用xcode 7.1。试试这段代码
void (^sendRequestsBlock)(void) = ^{
FBSDKGraphRequest *postRequest = nil;
NSDictionary *parameters = [NSDictionary dictionaryWithObject:@"id,email,first_name,last_name,name,picture{url}" forKey:@"fields"];
postRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters HTTPMethod:@"GET"];
[postRequest startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
if (!error) {
NSDictionary *dictResult = (NSDictionary *)result;
}
}];
};
/// login start
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
NSArray *permissions = [NSArray arrayWithObjects:@"email",@"public_profile", nil];
[login logInWithReadPermissions:permissions fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
} else if (result.isCancelled) {
} else {
if ([result.grantedPermissions containsObject:@"email"]) {
sendRequestsBlock();
}
}
}]