简体   繁体   English

为什么无法在我的iOS应用程序中对Facebook Chat进行身份验证?

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

I have been scouring the internet trying to find a solution to this problem. 我一直在搜寻互联网,以寻求解决此问题的方法。 I understand the basic idea on how it is supposed to work, but I can't get the implementation to work and I can't find any decent examples to help me. 我了解有关它应该如何工作的基本思想,但是我无法实现该实现,也找不到任何合适的示例来帮助我。 So far I have successfully been able to log in a user using the iOS 6 authentication mechanism, but I cannot figure out how to authenticate a user to the Jabber server from there. 到目前为止,我已经能够使用iOS 6身份验证机制成功登录用户,但是我无法弄清楚如何从那里对Jabber服务器进行身份验证。 Here is what I have: 这是我所拥有的:

After the user has logged in connect is called 用户登录后, 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()];
}

No matter what I try it always returns the same error: Error Domain=XMPPStreamErrorDomain Code=4 "The server does not support X-FACEBOOK-PLATFORM authentication." 不管我尝试什么,它总是返回相同的错误: Error Domain=XMPPStreamErrorDomain Code=4 "The server does not support X-FACEBOOK-PLATFORM authentication."

I am not incredibly familiar with either XMPP or the Facebook API so I'm sure there is something simple I am missing, but I have been working on this forever and been unable to make any progress. 我对XMPP或Facebook API都不是很熟悉,所以我确定我缺少一些简单的东西,但是我一直在努力,无法取得任何进展。 Any ideas? 有任何想法吗?

I found my answer. 我找到了答案。 In case anyone else runs into this same problem: I never actually told my XMPPStream to connect. 万一其他人遇到同样的问题:我从未真正告诉过XMPPStream进行连接。 I had tried all of the connect methods before, but they never worked. 我之前尝试过所有连接方法,但是它们从未起作用。 I now realize that I simply did not wait for them to finish connecting. 现在,我意识到我只是没有等他们完成连接。 Here is what I ended up changing: 这是我最终更改的内容:

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];
}

I realize that it's not the most elegant solution, but it works. 我意识到这不是最优雅的解决方案,但它可行。

make sure you use chat.facebook.com or facebook.com as the host name. 确保您使用chat.facebook.com或facebook.com作为主机名。

You must also open session with xmpp_login permission. 您还必须打开具有xmpp_login权限的会话。

For me the above host name worked 100% fine 对我来说,上述主机名有效100%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Facebook验证移动应用程序和底层服务器? - How can I authenticate my mobile application and underlying server using Facebook? 为什么我不能注册我的iOS应用程序来处理图像文件类型? - Why can't I register my iOS application to handle the image file type? 什么是XMPP,如何在iOS聊天应用程序中使用它? - What is XMPP, and how can I use it within an iOS chat application? 我无法对iOS应用程序进行代码签名 - I can't code sign my iOS application 为什么我的 iPhone 升级到 iOS 6 后无法在我的 iPhone 上进行测试? - Why can't I test on my iPhone after upgrading it to iOS 6? 无法在我的iOS应用程序中滚动 - Can't scroll in my iOS application iPhone Facebook应用程序用户遇到错误,我看不到,为什么? - iPhone facebook application user is getting an error I can't see, why? 如何在iOS中通过Facebook应用程序打开页面? - How can I open a page by Facebook application In iOS? iOS开发:为什么我不能将我的plist数据附加到我的MFMailComposeViewController? - iOS Development: Why can't I attach my plist data to my MFMailComposeViewController? 为什么Wingdings在iOS 5上不起作用? 为什么我的iPhone应用程序中不能使用Wingdings? - Why does Wingdings not function on iOS 5? Why can't I use Wingdings in my iPhone app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM