Android 使用C2DM获取401问题?

Android 使用C2DM获取401问题?,android,push,android-c2dm,Android,Push,Android C2dm,大家好! 我已经获得了手机的注册号和谷歌发给我的gmail账号的认证令牌,该账号正在执行推送操作 但是,当我将我的auth令牌和注册id发送到Ubuntu并尝试通过php发布它时,php的curl和only curl将请求发送到C2DM以获取消息。我总是得到401授权 这是我的php代码 $post_params = array ( "Email" => $MY_GOOGLE_ACC, "Passwd" => $MY_GOOGLE_PWD, "accountType"=>"G

大家好! 我已经获得了手机的注册号和谷歌发给我的gmail账号的认证令牌,该账号正在执行推送操作

但是,当我将我的auth令牌和注册id发送到Ubuntu并尝试通过php发布它时,php的curl和only curl将请求发送到C2DM以获取消息。我总是得到401授权

这是我的php代码

$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 = "";    

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

$size=strlen($data_msg); 

$x = curl_init("https://android.apis.google.com/c2dm/send");    
curl_setopt($x, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Content-Length:'. $size, 'Authorization: GoogleLogin auth=' . $authKey));
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; 
我是错过了什么还是做错了什么


任何帮助都将不胜感激,谢谢

似乎是从响应中提取SID,而不是从Auth字段中提取SID

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

$authKey = trim(substr($response, 5+strpos($response, "Auth=")));
尝试打印整个响应,您将看到如下内容:

SID=DQAAAGgA...7Zg8CTN
LSID=DQAAAGsA...lk8BBbG
Auth=DQAAAGgA...dk3fA5N
这是您要搜索的最后一个字段