1

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", "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());
    }
4

1 回答 1

1

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

“密码”参数名称实际上应该是“密码”。感谢丹农的回答。

于 2010-12-08T14:40:03.707 回答