我目前正在尝试使用iOS Facebook SDK 3.1实现Facebook-Login-Flow。 但它有一点问题。每次用户使用Facebook登录时,webview都会打开并显示
“您已经授权YOUR_APP ..”
我根据以下示例编写的代码:click here 现在我的问题是,我怎样才能避免这种行为以及我做错了什么?
答案 0 :(得分:1)
请参阅此代码,可能会有所帮助
postParams=
[@{
@"link" :link,
@"picture" :picture link , //[NSString stringWithFormat:@"%@%@",KBaseImageUrl,@"/assets/img/logo-small.jpg"],
@"name" : @“name”,
@"caption" : caption title,
@"description" :discription
} mutableCopy];
title=[[arrayEventInfo valueForKey:@"info"] valueForKey:@"eventname"];
if ([[FBSession activeSession]isOpen])
{
if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound)
{
[[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_action"] defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,NSError *error){
// If permissions granted, publish the story
[FBRequestConnection
startWithGraphPath:@"me/feed"
parameters:postParams
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error)
{
alertText = [NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code];
}
else
{
alertText = @"Posted successfully on your wall.";//[NSString stringWithFormat:
//@"Posted action, id: %@",
// result[@"id"]];
}
//Show the result in an alert
[[[UIAlertView alloc] initWithTitle:title
message:alertText
delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
}];
UIActivityIndicatorView *activityView=(UIActivityIndicatorView*)[self.view viewWithTag:111];
if(activityView)
{
[activityView removeFromSuperview];
}
[self.view setUserInteractionEnabled:YES];
[self.navigationController.navigationBar setUserInteractionEnabled:YES];
}];
}else
{
// If permissions granted, publish the story
[FBRequestConnection
startWithGraphPath:@"me/feed"
parameters:postParams
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error)
{
alertText = [NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code];
}
else
{
alertText = @"Posted successfully on your wall.";//[NSString stringWithFormat:
//@"Posted action, id: %@",
// result[@"id"]];
}
//Show the result in an alert
[[[UIAlertView alloc] initWithTitle:title
message:alertText
delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
}];
}
}
else
{
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
if (!error)
{
// If permissions granted, publish the story
[FBRequestConnection
startWithGraphPath:@"me/feed"
parameters:postParams
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error)
{
alertText = [NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code];
}
else
{
alertText = @"Posted successfully on your wall.";//[NSString stringWithFormat:
//@"Posted action, id: %@",
// result[@"id"]];
}
//Show the result in an alert
[[[UIAlertView alloc] initWithTitle:title
message:alertText
delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
}];
}
}else{
NSLog(@"%@",[error description]);
UIActivityIndicatorView *activityView=(UIActivityIndicatorView*)[self.view viewWithTag:111];
if(activityView)
{
[activityView removeFromSuperview];
}
[self.view setUserInteractionEnabled:YES];
[self.navigationController.navigationBar setUserInteractionEnabled:YES];
}
}];
}
答案 1 :(得分:-2)
如果您在dev中测试代码,那么您第一次登录时会将该会话存储在Facebook上。
因此,您尝试再次测试它,但它已经被授权。
如果您想再次测试登录过程,请转到Facebook并取消授权您的应用(它将在您的应用列表中)。
然后您可以再次登录设备。