C2DM Server with PHP 401 Error

by nino » Sat, 12 Feb 2011 06:03:25 GMT


Sponsored Links
 I'm building my own C2DM application right now. I first started with a
small Android application to test the push feature. And it works if I
just call the curl command with the correct settings in my shell.

Now for the server part I wanted to use PHP but as it seems I'm doing
something wrong as I always get a 401 error message when I try to send
a message to the client. First of all the code consists of two parts.
The first curl request asks for the server token. This works I get a
real response from google with a working token!

The second curl request ends up with a 401 error message. Any ideas
what I'm doing wrong?

  $post_params = array ( "Email" => $MY_GOOGLE_ACC, "Passwd" =>
$MY_GOOGLE_PWD, "accountType"=>"GOOGLE", "source=" . $MY_GOOGLE_SRC,
"service=ac2dm" );

  $first = true;
  $data_msg = "";

  foreach ($post_params as $key => $value) {
    if ($first)
      $first = false;
    else
      $data_msg .= "&";

    $data_msg .= urlencode($key) ."=". urlencode($value);
  }

  $x = curl_init("https://www.google.com/accounts/ClientLogin");

  curl_setopt($x, CURLOPT_HEADER, 1);
  curl_setopt($x, CURLOPT_POST, 1);
  curl_setopt($x, CURLOPT_POSTFIELDS, $data_msg);
  curl_setopt($x, CURLOPT_RETURNTRANSFER, 1);
  $data = curl_exec($x);
  curl_close($x);
  $response = $data;

  $authKey = trim(substr($response, 4+strpos($response, "SID=")));

  echo $authKey;
  $collapse_key = 'something';

  $post_params = array ( "registration_id" => $DEVICE_TOKEN,
"collapse_key" =>     $collapse_key, "data.payload"=>"cakephp" );

  $first = true;
  $data_msg = "";

-- 



Other Threads

1. 绛斿: [android-develo pers] Can I change the homesample code?

"it doesn't work" I mean when I run my new code ,the home screen doesn't
show as I want. It shows as the old.


€ome€€
4€ome€ 

----------
 android-developers@googlegroups.com
[EMAIL PROTECTED]  Mark Murphy
€ 200829:04
 android-developers@googlegroups.com
: [android-developers] Re: Can I change the homesample code?





Could you explain what you mean by "it doesn't work"? Are you getting
error messages during compiling, or at runtime?

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.1 Published!






----------------------------------------------------------------------------------------------
Confidentiality Notice: The information contained in this e-mail and any
accompanying attachment(s) is intended only for the use of the intended
recipient and may be confidential and/or privileged of Neusoft Corporation, its 
subsidiaries and/or its affiliates. If any reader of this communication is not 
the intended recipient, unauthorized use, forwarding, printing, storing, 
disclosure or copying is strictly prohibited, and may be unlawful. If you have 
received this communication in error, please immediately notify the sender by 
return e-mail, and delete the original message and all copies from your system. 
Thank you. 
-----------------------------------------------------------------------------------------------


--~--~---------~--~----~------------~-------~--~----~

2. Can I change the homesample code?

SDK 0.9 give the m15 home screen code, I try to change the code ,but it
doesn't work! Who can tell me why? 




----------------------------------------------------------------------------------------------
Confidentiality Notice: The information contained in this e-mail and any
accompanying attachment(s) is intended only for the use of the intended
recipient and may be confidential and/or privileged of Neusoft Corporation, its 
subsidiaries and/or its affiliates. If any reader of this communication is not 
the intended recipient, unauthorized use, forwarding, printing, storing, 
disclosure or copying is strictly prohibited, and may be unlawful. If you have 
received this communication in error, please immediately notify the sender by 
return e-mail, and delete the original message and all copies from your system. 
Thank you. 
-----------------------------------------------------------------------------------------------


--~--~---------~--~----~------------~-------~--~----~

3. Images

4. Icon Pack

5. SDK 0.9 camera issues

6. LocationManager.getCurrentLocation

7. Managed Dialogs