私はiOSを初めて使用し、アプリのFacebookログインを行いたいと思っています。
Facebookの新しいiOSSDKでたくさん試しました。しかし、私はエラーが発生しています。
コードは
-(IBAction)logIn:(id)sender;
{
AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appdelegate sessionOpener];
FBRequest *me = [FBRequest requestForMe];
[me startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *my,
NSError *error) {
NSLog(@"id %@", my.id);
NSLog(@"name %@", my.first_name);
greet.text = my.first_name;//this is a label to show the name
user.userID = my.id;//this is a FBProfilePictureView to show
}];
[UIView transitionFromView:self.view
toView:userPage
duration:0.5
options:(UIViewAnimationOptionTransitionFlipFromRight | UIViewAnimationOptionTransitionFlipFromLeft)
completion:NULL]; }
`
and sessionOpener is;
-(void) sessionOpener{
[FBSession sessionOpenWithPermissions:nil
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// session might now be open.
}];
}
今私が得るエラーは; ログイン後にアプリに最初にログインすると、値がnullを返し、http400エラーが発生します。
しかし、ログインした後、アプリを2回実行すると、情報がtrueになり、私の名前が出力されます。
私のシミュレーターiphone5.1シミュレーター