2016-05-07 107 views
1

我是gcm上游消息的新手。我试图通过xmpp(使用c#agsxmpp库)连接到云连接服务器。但是,即使相同的项目编号/ api键适用于http下游推送通知,我也会收到来自服务器的未授权错误消息,并且连接立即关闭。任何帮助表示赞赏。身份验证错误连接到谷歌云消息云连接服务器

这是代码。

 var username = Configuration.PROJECT_NUMBER + "@" + Configuration.GCM_SERVER; 
     xmpp = new XmppClientConnection 
     { 
      UseSSL = true, 
      UseStartTLS = false, 
      Server = Configuration.GCM_SERVER, 
      ConnectServer = Configuration.GCM_SERVER, 
      Port = Configuration.GCM_PORT, 
      Username = username, 
      Password = Configuration.GCM_API_KEY, 
      AutoResolveConnectServer = true, 
      SocketConnectionType = SocketConnectionType.Direct, 
      AutoAgents = false, 
      KeepAlive = true, 
      AutoRoster = false, 
      AutoPresence = false, 
      UseCompression = false, 
      Show = ShowType.chat 
     }; 

     xmpp.OnReadSocketData += Xmpp_OnReadSocketData; 
     xmpp.OnWriteSocketData += Xmpp_OnWriteSocketData; 
     xmpp.OnLogin += Xmpp_OnLogin; 
     xmpp.OnMessage += Xmpp_OnMessage; 
     xmpp.OnError += Xmpp_OnError; 
     xmpp.OnClose += Xmpp_OnClose; 
     xmpp.OnAuthError += Xmpp_OnAuthError; 

     xmpp.Open(); 

    } 

这里是与CCS我从<Project_Number>@<GCM_Server_Address>只是<Project_Number>更改用户名的相互作用(从OnReadSocketData和OnWriteSocketData事件捕获)

To CCS<<11:59:58 834 
<stream:stream to='gcm.googleapis.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'> 

From CSS>> 11:59:59 037 
<stream:stream from="gcm.googleapis.com" id="AF8BBDE576QWEFF3543" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">                                                                                               


From CSS>> 11:59:59 101 
<stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features>                                                                                                                                 


To CCS<<11:59:59 115 
<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">ADIwNjAxOTEwOTA2Mlw0MGjkdf4y67fvbjjdgESnhaa2tFX3hIcm56NXhWZndJclpFUmlMbnBqNVFIdkk=</auth> 


From CSS>> 11:59:59 312 
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>ism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features> 


From CSS>> 11:59:59 314 
</stream:stream>urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>ism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features>     
+0

你说你刚刚使用GCM上游消息传递的新功能,我是否正确地假设你正在实施的这一切都只是为了试用它?你正在使用'gcm-preprod.googleapis.com:5236'端口,那样的东西?只是想验证'Configuration.PROJECT_NUMBER' =''?干杯。 –

+0

找到了[相似文章](http://stackoverflow.com/q/32887244/4625829)。几乎没有差别:实施的语言和我以前的评论,他使用'gcm-preprod.googleapis.com'。我继续问他是否能找到导致他错误的原因。我不知道这是否有用。让我们来看看。干杯! –

+1

感谢您的帮助,我使用<项目编号> @作为用户名,我将其更改为仅用户名,现在正在工作。 – Yohannes

回答