如何获得使用城市飞艇的C2DM授权令牌

时间:2012-03-15 09:56:53

标签: android push-notification android-c2dm urbanairship.com

我想使用 Urban Airship的试用版推送通知
在Urban Pirship的注册申请页上,它需要 Google C2DM授权令牌。但我无法从谷歌获得C2DM授权令牌。我已经在谷歌注册了我的电子邮件ID以开始使用C2DM,但他们没有向我提供任何授权令牌..

如何从Google获得C2DM授权令牌?

3 个答案:

答案 0 :(得分:4)

访问此网站提供您的详细信息并获取您的C2DM授权令牌 HURL

答案 1 :(得分:0)

您必须等待大约24小时才能获得C2DM授权,有时甚至更多。但是,如果您可以使用curl获取令牌,则会收到一封确认电子邮件,如文档中所述。

答案 2 :(得分:0)

您需要使用Google ClientLogin HTTP API使用您的C2DM帐户电子邮件和密码来请求身份验证令牌:

public static String getClientLoginAuthToken() {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://www.google.com/accounts/ClientLogin");
try {
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
    nameValuePairs.add(new BasicNameValuePair("Email", "C2DMEMAILADDRESS));
    nameValuePairs.add(new BasicNameValuePair("Passwd", "C2DMPASSWORD));
    nameValuePairs.add(new BasicNameValuePair("accountType", "GOOGLE"));
    nameValuePairs.add(new BasicNameValuePair("source", "Google-cURL-Example"));
    nameValuePairs.add(new BasicNameValuePair("service", "ac2dm"));
    post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = client.execute(post);
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String line = "";
    while ((line = rd.readLine()) != null) {
        Trace.e("HttpResponse", line);
        if (line.startsWith("Auth=")) {
            return line.substring(5);
        }
    }
} catch (IOException e) {
    e.printStackTrace();
}
Trace.e(TAG, "Failed to get C2DM auth code");
return "";
}

有关身份验证令牌的更多信息,请参阅本教程: http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html