C2DM服务器端ClientLogin与java问题

发布于 2024-10-06 12:00:04 字数 1530 浏览 0 评论 0原文

我正在尝试实现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沒落の蓅哖 2024-10-13 12:00:04

我的问题在这里向我指出:
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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文