【问题标题】:How to get C2DM Authorization Token for using Urban Airship如何获取使用 Urban Airship 的 C2DM 授权令牌
【发布时间】:2012-03-31 19:46:49
【问题描述】:

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

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

【问题讨论】:

  • 感谢@OllieC,但当它对我有用时,我接受它作为答案,因为寻找相同问题的其他人主要关注已接受的答案。所以我不能接受不正确的答案。谢谢顺便说一句

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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您必须等待大约 24 小时才能获得 C2DM 授权,有时甚至更长时间。但是,当您可以按照文档中的说明使用 curl 获取令牌时,您将收到一封确认电子邮件。

    【讨论】:

    • 这是不正确的。首先,C2DM 帐户通常几乎立即获得批准。其次,Google 不会主动发送 auth-token,它必须从 ClientLogin API 请求(并且过期,因此需要重复执行)
    【解决方案3】:

    您需要使用 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

    【讨论】:

    • 我需要在安卓或服务器端获取授权令牌吗?
    • 在服务器端。上面的示例代码是 Android 代码 - 我使用它是为了在应用程序中构建一个测试工具来向其自身发送推送消息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-11
    • 2015-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多