1
我想實現C2DM的服務器端。我通過註冊程序向Google註冊了我的應用程序,並收到了電子郵件確認,所以我的用戶/密碼應該很好。第一步是通過ClientLogin檢索授權令牌。當我運行代碼時,我得到一個響應代碼403/Forbidden。有人有主意嗎?C2DM服務器端ClientLogin與java問題
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());
}
嗯,我也得到了403也,但所有參數correc ...並沒有額外的信息在響應 – Ted 2011-12-04 11:56:25