【问题标题】:Facebook publish on wall ,It is taking two requests first time in IPhone?Facebook 在墙上发布,第一次在 iPhone 中需要两个请求?
【发布时间】:2012-01-18 06:35:33
【问题描述】:

我正在使用 facebook api 来分享 facebook。我正在使用

[self.facebook 对话:@"feed" andParams:params andDelegate:self];

按钮操作。但第一次显示弹出窗口但立即关闭。它在控制台中显示错误。这里的问题是它一次打开两个请求。这些请求也是相同的。但第二次打开正常(没有问题也没有错误)。如何忽略这一点,第一次只打开一个请求?

【问题讨论】:

    标签: iphone objective-c ios4 facebook


    【解决方案1】:

    您是否在显示提要对话框之前授权用户?我帮助了另一个不久前遇到同样问题的人:Facebook iOS SDK - Strange Effects in Writing to Status

    如果是这种情况,授权和显示对话框都会触发要显示的对话框。您必须确保一次只执行一项(身份验证 > 等待成功 > 显示提要对话框)。

    编辑:这几乎就是我的做法:

    MyClass.h

    我保存要共享的对象的实例变量(如果需要授权):

    MyObject *_objectToShare;
    ...
    @property (nonatomic, retain) MyObject *objectToShare; // @synthesized in MyClass.m
    

    MyClass.m

    用于共享对象的方法(通过NSNotification):

    /**
     * Method invoked to share an object on Facebook.
     */
    - (void)shareObject:(NSNotification *)note {
    
        // show dialog if authorized, otherwise authenticate first
        if ([_facebook isSessionValid]) {
            // Use Facebook share dialog
            NSMutableDictionary *params = [NSMutableDictionary dictionary]; // define key-value params to send to FB
    
            // show feed dialog
            [_facebook dialog:@"feed" andParams:params andDelegate:self];
    
            // Clear object to share (as it's been shared now)
            self.objectToShare = nil;
        }
        else {
            // authorize with defined permissions
            [_facebook authorize:[NSArray arrayWithObjects:@"publish_stream", @"publish_actions", nil]]; // the permissions you need (@see http://developers.facebook.com/docs/reference/api/permissions/)
    
            // save a reference to the track to share (after auth is done)
            self.objectToShare = channel;
        }
    
    }
    

    在用户获得 Facebook 授权后共享对象:

    /**
     * From FBSessionDelegate. Invoke method to share object if any is defined.
     */
    - (void)fbDidLogin {
        // share queued object if it's defined
        if (self.objectToShare) {
            [self shareObject:nil]; // don't pass any notification
        }
    }
    

    【讨论】:

    • 你能在代码中告诉我。我需要在点击需要在墙上发布的按钮时写吗?
    • 什么是kFACEBOOK_PERMISSIONS宏,我们需要在哪里定义?
    • 我们需要写 [_facebook authorize:permissions]; [_facebook 对话:@"feed" andParams:params andDelegate:self]; IBAction 中的这些方法?
    • kFACEBOOK_PERMISSIONS 是一个 NSArray,具有您的 FB 集成所需的权限,即[NSArray arrayWithObjects:@"publish_stream", @"publish_actions", nil]。有关更多信息,请参阅 FB 文档:developers.facebook.com/docs/reference/api/permissions
    • 您可以在您的IBAction 中调用-shareObject:(如果您想从那里显示对话框)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-04
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    相关资源
    最近更新 更多