C2DM服务器端ClientLogin与java问题

时间:2010-12-07 21:28:03

标签: android-c2dm

我正在尝试实现C2DM的服务器端。我通过注册过程向Google注册了我的申请,并收到了确认电子邮件,因此我的用户/ pwd应该是好的。第一步是通过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", "MY_ACCOUNT@gmail.com"));
        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());
    }

1 个答案:

答案 0 :(得分:1)

我的问题在这里指出: http://blog.boxedice.com/2010/10/07/android-push-notifications-tutorial/

“密码”参数名称实际上应为“密码”。 感谢Dannon的回答。