我使用以下代码从Facebook获取数据到我的应用程序。 我在app delegate和plist中做了所有其他的事情。 这有时会起作用并获取数据,有时候也不会。谁能帮我这个。我无法确定问题所在!
- (IBAction)facebook:(id)sender
{
FBLoginView *loginView=[[FBLoginView alloc]init];
loginView.delegate=self;
loginView.readPermissions = @[@"first_name",
@"last_name",
@"location",
@"id",
@"access_token"];
NSArray* permissions = [NSArray arrayWithObjects: @"email", nil];
loginView.readPermissions=permissions;
[FBSession openActiveSessionWithAllowLoginUI:YES];
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection,
id<FBGraphUser> user1,
NSError *error) {
if (!error) {
firstname=user1.first_name;
lastname=user1.last_name;
city=[user1.location objectForKey:@"name"];
email=user1[@"email"];
fbid=user1.id;
Loggedin=@"Y";
[[NSUserDefaults standardUserDefaults]setObject:Loggedin forKey:@"token"];
[[NSUserDefaults standardUserDefaults]synchronize];
}
if (![fbid isEqualToString:@""])
{
[self performSegueWithIdentifier: @"Facebooksegue" sender: self];
}
NSLog(@"%@",firstname);
NSLog(@"%@",lastname);
NSLog(@"%@",city);
NSLog(@"%@",email);
NSLog(@"%@",fbid);
}];
}
我的AppDelegate
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FBSession class];
return YES;
}
答案 0 :(得分:1)
转到左上角的蓝色项目图标,选择目标,转到构建设置,查找其他链接器标志,添加-ObjC。这将使整个框架静态链接,因此您可以成功地在故事板中引用FBLoginView。
答案 1 :(得分:1)
我有类似的情况,我使用了几乎相同的代码。 我的问题是我用过的测试Facebook ID。我没有经过验证,所以它没有回复电子邮件。尝试使用其他帐户,它可能会有效。如果没有,请检查您的应用是否获得授权,并在设置中将Facebook帐户与您的帐户同步。 希望这会有所帮助。