Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在Facebook(IOS)中使用SSO发布提要_Iphone_Facebook_Xcode4_Single Sign On_Facebook Ios Sdk - Fatal编程技术网

Iphone 在Facebook(IOS)中使用SSO发布提要

Iphone 在Facebook(IOS)中使用SSO发布提要,iphone,facebook,xcode4,single-sign-on,facebook-ios-sdk,Iphone,Facebook,Xcode4,Single Sign On,Facebook Ios Sdk,我正在进行Facebook集成,并尝试使用发布源功能进行单点登录。 我正在使用最新的FacebookSDK。我有Facebook的Hackbook示例代码,但我对所有这些都是新手,所以很难完全理解所有这些内容 在搜索SSO时,我得到了一些代码,它运行良好。这是我正在使用的代码(在本页末尾附有源代码) ViewController.m - (IBAction)publishFeed:(id)sender { //For SSO [[FBUtils sharedFBUtils] initia

我正在进行Facebook集成,并尝试使用发布源功能进行单点登录。
我正在使用最新的FacebookSDK。我有Facebook的Hackbook示例代码,但我对所有这些都是新手,所以很难完全理解所有这些内容

在搜索SSO时,我得到了一些代码,它运行良好。这是我正在使用的代码(在本页末尾附有源代码)

ViewController.m

- (IBAction)publishFeed:(id)sender { 

//For SSO

[[FBUtils sharedFBUtils] initializeWithAppID:@"3804765878798776"];
NSArray *permision = [NSArray arrayWithObjects:@"read_stream",@"publish_stream", nil];
[[FBUtils sharedFBUtils] LoginWithPermisions:permision];
[FBUtils sharedFBUtils].delegate = self;
FBSBJSON *jsonWriter = [FBSBJSON new];


/// for publishfeed

    NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
                                                  @"Get Started",@"name",@"https://itunes.apple.com?ls=1&mt=8",@"link", nil], nil];
    NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
    // Dialog parameters
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"I have lot of fun preparing.", @"name",
                               @" exam", @"caption",
                               @" ", @"description",
                               @"https://itunes.apple.com", @"link",
                               @"http://mypng", @"picture",
                               actionLinksStr, @"actions",
                               nil];

    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [[delegate facebook] dialog:@"feed"
                      andParams:params
                    andDelegate:self];
当我点击应用程序中的Facebook按钮时,它会将我重定向到Facebook,然后重新调谐回我的应用程序。现在,我想要的是在返回应用程序后立即触发publishFeed事件,它应该直接向用户请求post或取消选项。但它要求再次像这样登录

有人能帮我吗?或者请给我建议正确的方法。

你的建议会有很大帮助。

在你的方法中,你没有检查应用程序是否有发布帖子的权限,以及用户是否在之前登录。因此,每次你调用此方法时,应用程序都希望你登录。我认为这就是问题所在

如果我是对的,您需要像这样在方法中添加权限和登录控制。这是我从另一个项目中获得的示例代码,您可以获得它背后的逻辑

- (IBAction)facebookShare:(id)sender
{

    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

    // You check the active session here.
    if (FBSession.activeSession.isOpen)
    {
             // You check the permissions here.
             if ([FBSession.activeSession.permissions
             indexOfObject:@"publish_actions"] == NSNotFound) {
            // No permissions found in session, ask for it
            [FBSession.activeSession
             reauthorizeWithPublishPermissions:
             [NSArray arrayWithObject:@"publish_actions"]
             defaultAudience:FBSessionDefaultAudienceFriends
             completionHandler:^(FBSession *session, NSError *error) {
                 if (!error) {
                     // If permissions granted, publish the story
                     [self postFacebook];

                     [[[UIAlertView alloc] initWithTitle:@"Result"
                                                 message:@"Posted in your wall."
                                                delegate:self
                                       cancelButtonTitle:@"OK"
                                       otherButtonTitles:nil]
                      show];
                 }
             }];
        } else {
            // If permissions present, publish the story
            [self postFacebook]; // ------> This is your post method.

            [[[UIAlertView alloc] initWithTitle:@"Sonuç"
                                        message:@"Duvarında paylaşıldı."
                                       delegate:self
                              cancelButtonTitle:@"Tamam"
                              otherButtonTitles:nil]
             show];
        }
    }

    else
    {
     // If there is no session, ask for it.
     [appDelegate openSessionWithAllowLoginUI:YES];
    }


    // NSLog(@"Post complete.");

}