我正试图在iOS中使用Facebook SDK将消息发布到Facebook墙上。成功登录后,在发布到Facebook之前不会询问用户权限。我在iOS sdk中使用请求新的发布权限方法向所有权限发出了请求。当我点击发布消息时,任何机构都有关于如何显示用户权限屏幕的想法?
以下是我使用的代码:
//Login:
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if(!error) {
if(state == FBSessionStateOpen)
[self postWithText: @"message"
ImageName: @""
URL: @""
Caption: @""
Name: @""
andDescription: @""];
} else {
[FBSession.activeSession closeAndClearTokenInformation];
//show error message }
}];
-(void) postWithText: (NSString*) message
ImageName: (NSString*) image
URL: (NSString*) url
Caption: (NSString*) caption
Name: (NSString*) name
andDescription: (NSString*) description
{
NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
message, @"message",
nil];
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound)
{
// No permissions found in session, ask for it
[FBSession.activeSession requestNewPublishPermissions: [NSArray arrayWithObject:@"publish_actions"]
defaultAudience: FBSessionDefaultAudienceFriends
completionHandler: ^(FBSession *session, NSError *error)
{
if (!error)
{
[self postToWall: params];
}
}];
}
else
{
[self postToWall: params];
}
}
-(void) postToWall: (NSMutableDictionary*) params
{
[FBRequestConnection startWithGraphPath:@"me/feed"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Post Failed"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}];
}
答案 0 :(得分:1)
[[FBSession activeSession] isOpen]
进行了测试。在requestNewPublishPermissions
上放置断点并检查它是否被调用(可能是只是以你没有捕获的错误结束。你可能也想检查这个答案。