Android的C2DM获得(401)未经授权未经授权、Android、C2DM

2023-09-13 23:50:31 作者:温柔许愿者

我有一个Android应用程序与ASP.NET后端。我有registration_id的电话以及来自谷歌的身份验证令牌对于正在执行推送应用程序服务器。

I have an Android application with an ASP.NET backend. I have the registration_id for the phone as well as an auth token from google for the application server that is performing a push.

当我做了HTTP POST请求C2DM让手机得到一个消息,我不断收到401未授权。下面是我做的.NET请求:

When I make the http post request to C2DM so that the phone gets a message I keep getting the 401 Unauthorized. Here is how I'm making the request in .NET:

    WebRequest myRequest = WebRequest.Create("https://android.apis.google.com/c2dm/send");
    myRequest.ContentType = "application/x-www-form-urlencoded";
    myRequest.Method = "POST";
    myRequest.Headers.Add("Authorization", "GoogleLogin auth=" + authId);
    // buiold the post string
    StringBuilder myPost = new StringBuilder();
    myPost.AppendFormat("registration_id={0}", regId);
    myPost.AppendFormat("&data.payload={0}", msg);
    myPost.AppendFormat("&collapse_key={0}", colKey);

    // write the post-string as a byte array
    byte[] myData = ASCIIEncoding.ASCII.GetBytes(myPost.ToString());
    myRequest.ContentLength = myData.Length;
    Stream myStream = myRequest.GetRequestStream();
    myStream.Write(myData, 0, myData.Length);
    myStream.Close();
    // Do the actual request and read the response stream
    WebResponse myResponse = myRequest.GetResponse();
    Stream myResponseStream = myResponse.GetResponseStream();
    StreamReader myResponseReader = new StreamReader(myResponseStream);
    string strResponse = myResponseReader.ReadToEnd();
    myResponseReader.Close();
    myResponseStream.Close();

任何帮助将是非常美联社preciated。

Any help would be much appreciated.

推荐答案

建议角落:有一定的信心的code每一次,一段时间!而且,即使谷歌食堂了的时候。

Advice corner: Have some confidence in your code every once and a while! And, even Google messes up sometimes.

开支大约九小时的阅读每一个博客帖子和文章关于谷歌的OAuth和C2DM,并试图在我的code不同的事情后,我给谷歌。我很高兴地说,我不仅很快得到回复,还以为我的帐户被搞砸了。出事了,而我是登记在其网站上,虽然它似乎一切都从我收到的注册成功的电子邮件的工作,事实并非如此。我重新注册,一切正常!

After spending about nine hours reading every blog post and article about Google OAuth and C2DM and trying different things in my code, I emailed Google. I'm excited to say that not only did I receive a response very quickly, but also that my account was messed up. Something went wrong while I was registering on their site and although it appeared that everything was working from the registration success email I received, it wasn't. I re-registered and everything works!