4

I want to Use Trial version of Urban Airship for Push notification.
On registering application page of Urban Airship it require Google C2DM Authorization Token. but i am not able to get the C2DM Authorization Token from Google. i have registered my email ID with google to start using C2DM but they did not provide me any Authorization Token..

how can i get C2DM Authorization Token from Google?

waseemwk
  • 1,499
  • 3
  • 15
  • 44
  • Thanks @OllieC but i accept as answer when it is working for me because other people searching for the same problem focus mainly on accepted answer. so i cannot accept answer which is not correct. thanks btw – waseemwk Mar 15 '12 at 11:36

3 Answers3

4

Visit this site give your details and get your C2DM authorization token HURL

Mukesh Kumar
  • 611
  • 7
  • 17
0

You have to wait around 24 hours to get authorized for C2DM, sometimes more. But you will receive an email for confirmation when you can get your token using curl as explained in the docs.

Snicolas
  • 37,840
  • 15
  • 114
  • 173
  • This isn't correct. First the C2DM accounts are usually approved almost immediately. Second, Google do not proactively send an auth-token, it has to be requested from the ClientLogin API (and it expires, so this needs doing repeatedly) – Ollie C Mar 15 '12 at 10:09
0

You need to use the Google ClientLogin HTTP API to request an auth token, using your C2DM account email and password:

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 "";
}

For more information on the auth token, see this tutorial: http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html

Ollie C
  • 28,313
  • 34
  • 134
  • 217
  • do i need to get authorization Token on android or server side ? – waseemwk Mar 15 '12 at 16:18
  • On the server-side. The sample code above is Android code - I used it so I could build a test harness in the app to send push emssages to itself. – Ollie C Mar 15 '12 at 16:23