开发者

Android 401 for c2dm

开发者 https://www.devze.com 2023-02-22 11:34 出处:网络
I got registration_id and authoCode using same gmail id but still I\'m getting \"Unauthorized\". I am clueless now what can be wrong.

I got registration_id and authoCode using same gmail id but still I'm getting "Unauthorized". I am clueless now what can be wrong.

While Sign Up for Android Cloud to Device Messaging. If I'm using abc@gmail.com, I am using same abc@gmail.com in

Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
registrationIntent.putExtra("sender", "abc@gmail.com");
this.startService(registrationIntent);

same for the while getting authCode

https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email=abc@gmail.com&Passwd=XXXXX&source=XXXXXXX-0.1&service=cl

Code I am using is

$headers = array('Authorization: GoogleLogin auth=' . $authCode);
$data = array(
    'registration_id' => $registrationId,
    'collapse_key' => "test",
    'data.m开发者_运维百科essage' => "wass up" //TODO Add more params with just simple data instead
);

print_r($headers);
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://android.apis.google.com/c2dm/send");
if ($headers)
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$response = curl_exec($ch);

curl_close($ch);
echo($response);
return $response;

These are the steps I followed

  1. I created a new google account for my app
  2. Registered it with http://code.google.com/android/c2dm/signup.html
  3. First ran the app on the simulator to get the registration id
  4. Used the same gmail id to get the authCode
  5. After getting authCode and RegistartionId, I am trying to send the message.

Am I missing any steps?


Ok this was bad on my side.

The code is good but i was asking auth code for wrong service

for all those ppl like me who just copy/paste example

for c2dm

https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email=XXXXX&Passwd=XXXXX&source=Google&service=ac2dm

In google doc they have given example for google calendar service=cl

hope this help anyone

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号