C2DM服务器端ClientLogin与java问题
我正在尝试实现 C2DM 的服务器端。我已经通过注册过程向 Google 注册了我的应用程序,并收到了一封确认电子邮件,所以我的用户/密码应该是好的。第一步是通过 ClientLogin 检索身份验证令牌。当我运行代码时,我收到响应代码 403/Forbidden。有人有什么想法吗?
log.info("Obtaining the Google C2DM Client Login token.");
// Make POST request
HttpResponse res = null;
try {
DefaultHttpClient client = new DefaultHttpClient();
URI uri = new URI("https://www.google.com/accounts/ClientLogin");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("accountType", "HOSTED_OR_GOOGLE"));
params.add(new BasicNameValuePair("Email", "[email protected]"));
params.add(new BasicNameValuePair("Password", "MY_PWD"));
params.add(new BasicNameValuePair("service", "ac2dm"));
params.add(new BasicNameValuePair("source", "MY_APP-V0.1"));
HttpPost post = new HttpPost(uri);
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
post.setEntity(entity);
res = client.execute(post);
} catch (Exception e) {
log.error("Error obtaining the Google C2DM Client Login token.", e);
}
log.debug("response="+res);
if (res != null) {
log.debug("Response status code = "+res.getStatusLine().getStatusCode());
log.debug("Response status = "+res.getStatusLine().getReasonPhrase());
}
I'm trying to implement the server side of C2DM. I have registered my application with Google via the signup process and received an email confirmation, so my user/pwd should be good. The first step is to retrieve the auth token via the ClientLogin. When I run the code, I get a response code 403 / Forbidden. Anyone have any ideas?
log.info("Obtaining the Google C2DM Client Login token.");
// Make POST request
HttpResponse res = null;
try {
DefaultHttpClient client = new DefaultHttpClient();
URI uri = new URI("https://www.google.com/accounts/ClientLogin");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("accountType", "HOSTED_OR_GOOGLE"));
params.add(new BasicNameValuePair("Email", "[email protected]"));
params.add(new BasicNameValuePair("Password", "MY_PWD"));
params.add(new BasicNameValuePair("service", "ac2dm"));
params.add(new BasicNameValuePair("source", "MY_APP-V0.1"));
HttpPost post = new HttpPost(uri);
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
post.setEntity(entity);
res = client.execute(post);
} catch (Exception e) {
log.error("Error obtaining the Google C2DM Client Login token.", e);
}
log.debug("response="+res);
if (res != null) {
log.debug("Response status code = "+res.getStatusLine().getStatusCode());
log.debug("Response status = "+res.getStatusLine().getReasonPhrase());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的问题在这里向我指出:
http://blog.boxedice.com/2010/10/ 07/android-push-notifications-tutorial/
“Password”参数名称实际上应该是“Passwd”。
感谢丹农的回答。
My problem was pointed out to me here:
http://blog.boxedice.com/2010/10/07/android-push-notifications-tutorial/
The "Password" parameter name should actually be "Passwd".
Thanks to Dannon for the answer.