【问题标题】:Publish Feed with SSO in Facebook (IOS)在 Facebook (IOS) 中使用 SSO 发布 Feed
【发布时间】:2012-11-30 01:48:20
【问题描述】:

我正在研究 Facebook 集成并尝试使用发布提要功能进行单点登录。
我正在使用最新的 FacebookSDK。我有 Facebook 的 Hackbook 示例代码,但是我对这一切都很陌生,所以很难完全理解所有这些东西。

在 SSO 上搜索时,我得到了一些代码,它工作正常。这是我正在使用的代码(在本页末尾附有源代码)

FBUtils.h and FBUtils.m class

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 事件,它应该直接向用户询问发布或取消选项。但它要求像这样再次登录。

任何人都可以帮助我,或者请给我正确的建议。
您的建议会很有帮助。

【问题讨论】:

    标签: iphone facebook xcode4 single-sign-on facebook-ios-sdk


    【解决方案1】:

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

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

    - (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.");
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多