[英]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.