簡體   English   中英

為什么無法在我的iOS應用程序中對Facebook Chat進行身份驗證?

[英]Why can't I authenticate to Facebook Chat in my iOS application?

我一直在搜尋互聯網,以尋求解決此問題的方法。 我了解有關它應該如何工作的基本思想,但是我無法實現該實現,也找不到任何合適的示例來幫助我。 到目前為止,我已經能夠使用iOS 6身份驗證機制成功登錄用戶,但是我無法弄清楚如何從那里對Jabber服務器進行身份驗證。 這是我所擁有的:

用戶登錄后, connect調用connect

-(void)connect
{
    [self setupStream];
    NSError *error = nil;
    [_xmppStream authenticateWithFacebookAccessToken: FBSession.activeSession.accessTokenData.accessToken error:&error];
    NSLog(@"%@", error);
    [NSString stringWithFormat:@"%@", self];
}

-(void)newSetupStream
{
    _xmppStream = [[XMPPStream alloc] initWithFacebookAppId:@"611051652253156"];

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


    _xmppReconnect = [[XMPPReconnect alloc] init];


    _xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] init];

    _xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:_xmppRosterStorage];
    _xmppRoster.autoFetchRoster = YES;
    _xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;


    _xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
    _xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:_xmppvCardStorage];
    _xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:_xmppvCardTempModule];


    _xmppCapabilitiesStorage = [XMPPCapabilitiesCoreDataStorage sharedInstance];
    _xmppCapabilities = [[XMPPCapabilities alloc] initWithCapabilitiesStorage:_xmppCapabilitiesStorage];
    _xmppCapabilities.autoFetchHashedCapabilities = YES;
    _xmppCapabilities.autoFetchNonHashedCapabilities = NO;


    [_xmppReconnect         activate:_xmppStream];
    [_xmppRoster            activate:_xmppStream];
    [_xmppvCardTempModule   activate:_xmppStream];
    [_xmppvCardAvatarModule activate:_xmppStream];
    [_xmppCapabilities      activate:_xmppStream];


    [_xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [_xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
}

不管我嘗試什么,它總是返回相同的錯誤: Error Domain=XMPPStreamErrorDomain Code=4 "The server does not support X-FACEBOOK-PLATFORM authentication."

我對XMPP或Facebook API都不是很熟悉,所以我確定我缺少一些簡單的東西,但是我一直在努力,無法取得任何進展。 有任何想法嗎?

我找到了答案。 萬一其他人遇到同樣的問題:我從未真正告訴過XMPPStream進行連接。 我之前嘗試過所有連接方法,但是它們從未起作用。 現在,我意識到我只是沒有等他們完成連接。 這是我最終更改的內容:

NSError *error;
NSError *err;
[_xmppStream connectWithTimeout:10.00 error:&err];

[_xmppStream authenticateWithFacebookAccessToken: FBSession.activeSession.accessTokenData.accessToken error:&error];
while (error)
{
    sleep(1);
    [_xmppStream authenticateWithFacebookAccessToken: FBSession.activeSession.accessTokenData.accessToken error:&error];
}

我意識到這不是最優雅的解決方案,但它可行。

確保您使用chat.facebook.com或facebook.com作為主機名。

您還必須打開具有xmpp_login權限的會話。

對我來說,上述主機名有效100%

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM