0

我已经在 iPhone 中创建了一个用于 facbook 聊天的示例应用程序xmpp framework,它运行良好,但是当我将它集成到主项目中时,它显示以下错误服务器不支持 X-FACEBOOK-PLATFORM 身份验证下面是我的代码

- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
    NSError *error;
    if (![xmppStream isSecure])
    { 
        NSError *error = nil;
        BOOL result = [xmppStream secureConnection:&error];
        if (result == NO)
        {

        }
    }
    else
    {
        [xmppStream authenticateWithFacebookAccessToken:FBSession.activeSession.accessTokenData.accessToken error:&error];
        NSLog(@"%@",error);          
    }
}
4

1 回答 1

0

您需要执行以下步骤:

首先,使用 app id 创建 Facebook 流:

- (void)setupStreamFacebook
{

    //NSAssert(xmppStream == nil, @"Method setupStream invoked multiple times");

    // Setup xmpp stream
    //
    // The XMPPStream is the base class for all activity.
    // Everything else plugs into the xmppStream, such as modules/extensions and delegates.
    NSAssert(nil != self.facebookAppId, @"Please setup facebook app id");
    NSAssert(nil != self.facebookToken, @"Please pass facebook access token");

    xmppStreamFacebook = [[XMPPStream alloc] initWithFacebookAppId:self.facebookAppId];



#if !TARGET_IPHONE_SIMULATOR
    {       
        xmppStream.enableBackgroundingOnSocket = YES;
    }
#endif

    // Setup reconnect
    xmppReconnectFacebook = [[XMPPReconnect alloc] init];

    // Setup roster 

        xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] initWithInMemoryStore];

    if (!xmppRosterFacebook) {
        xmppRosterFacebook = [[XMPPRoster alloc] initWithRosterStorage:xmppRosterStorage];
    }

    xmppRosterFacebook.autoFetchRoster = YES;
    xmppRosterFacebook.autoAcceptKnownPresenceSubscriptionRequests = YES;

    // Setup vCard support

    if (!xmppvCardTempModule) {
        xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:xmppvCardStorage];
    }

    if (!xmppvCardAvatarModule) {
        xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:xmppvCardTempModule];
    }


    if (!xmppCapabilities) {
        xmppCapabilities = [[XMPPCapabilities alloc] initWithCapabilitiesStorage:xmppCapabilitiesStorage];
    }


    xmppCapabilities.autoFetchHashedCapabilities = YES;
    xmppCapabilities.autoFetchNonHashedCapabilities = NO;

    // Activate xmpp modules

    [xmppReconnectFacebook         activate:xmppStreamFacebook];
    [xmppRosterFacebook            activate:xmppStreamFacebook];
    [xmppvCardTempModule   activate:xmppStreamFacebook];
    [xmppvCardAvatarModule activate:xmppStreamFacebook];
    [xmppCapabilities      activate:xmppStreamFacebook];

    // Add ourself as a delegate to anything we may be interested in

    [xmppStreamFacebook addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [xmppRosterFacebook addDelegate:self delegateQueue:dispatch_get_main_queue()];


    // You may need to alter these settings depending on the server you're connecting to
    allowSelfSignedCertificates = NO;
    allowSSLHostNameMismatch = NO;

    NSError *fbError = nil;

}

然后,生成 Facebook 访问令牌并将其传递给以下方法:

[xmppStreamFacebook authenticateWithFacebookAccessToken:self.facebookToken error:&fbError];
// NSLog(@"facebook erro = %@",error);
[xmppStreamFacebook connectWithTimeout:5 error:&fbError];

更新以下代表:

- (void)xmppStreamDidConnect:(XMPPStream *)sender
{
    NSLog(@"%@: %@", THIS_FILE, THIS_METHOD);
    NSLog(@"Stream Host: %@", sender.hostName);
    if ([sender isEqual:xmppStreamFacebook])
    {
        if (![xmppStreamFacebook isSecure])
        {
            NSLog(@"       if (![xmppStreamFacebook isSecure])");
            NSError *error = nil;
            BOOL result = [xmppStreamFacebook secureConnection:&error];
            
            if (result == NO)
            {
                NSLog(@"%@: Error in xmpp STARTTLS: %@", THIS_FILE, error);
            }
        }
        else
        {
            NSLog(@"authenticateWithFacebookAccessToken");
            NSError *error = nil;
            BOOL result = [xmppStreamFacebook authenticateWithFacebookAccessToken:self.facebookToken error:&error];
            
            if (result == NO)
            {
                NSLog(@"%@: Error in xmpp auth: %@", THIS_FILE, error);
            }
        }
        
    }
}

- (void)xmppStream:(XMPPStream *)sender willSecureWithSettings:(NSMutableDictionary *)settings
{
    NSLog(@"%@: %@", THIS_FILE, THIS_METHOD);
    if ([sender isEqual:xmppStreamFacebook])
    {
        NSLog(@"do not secure facebook");
        return;
    }
}

它会正常工作。

于 2013-12-23T12:27:45.300 回答