我正在尝试将 facebook 集成到我的 iOS 5 应用程序中。正如 facebook 文档中提到的,我正在按照他们提到的那样做所有事情。通常当facebook发起授权时,它会将用户带到浏览器打开facebook网站并要求进行身份验证。但在我的情况下,它会打开浏览器并立即返回应用程序。我不明白发生了什么。
它没有在facebook上发布任何内容。它只是过渡到本机应用程序,然后又回来了。
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"])
{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"SELECT uid, name, pic, email FROM user WHERE uid=me()", @"query",nil];
[facebook requestWithMethodName:@"fql.query"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Facebook"
message:@"You are successfully signed in."
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil,
nil];
[self performSelector:@selector(dismissAlertView:) withObject:alertView afterDelay:2];
[alertView show];
NSLog(@"signed in");
}
if (![facebook isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_likes",
@"read_stream",
@"publish_stream",
nil];
[facebook authorize:permissions];
[permissions release];
}
else if ([facebook isSessionValid]) { facebookOut.hidden=NO;
}