在凭证方面,我创建了在引用中键入0.0.0.0的浏览器API密钥.实际上我创建了两种类型的键,因为我在不同的教程中找到了不同的指示.
browser-key picture
server-key picture
我用这个PHP脚本测试了密钥
<?/** * The following function will send a GCM notification using curl. * * @param $APIKey [string] The browser API key string for your GCM account * @param $registrationIDsArray [array] An array of registration IDs to send this notification to * @param $messageData [array] An named array of data to send as the notification payload */function sendNotification( $APIKey,$registrationIDsArray,$messageData ){ $headers = array("Content-Type:" . "application/Json","Authorization:" . "key=" . $APIKey); $data = array( 'data' => $messageData,'registration_IDs' => $registrationIDsArray ); $ch = curl_init(); curl_setopt( $ch,CURLOPT_httpheader,$headers ); curl_setopt( $ch,CURLOPT_URL,"https://androID.GoogleAPIs.com/gcm/send" ); curl_setopt( $ch,CURLOPT_SSL_VERIFYHOST,0 ); curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER,CURLOPT_RETURNTRANSFER,true ); curl_setopt( $ch,CURLOPT_POSTFIELDS,Json_encode($data) ); $response = curl_exec($ch); curl_close($ch); return $response;}?><?// Message to send$message = "the test message";$tickerText = "ticker text message";$contentTitle = "content Title";$contentText = "content body";$registrationID = '372CBFD0C4BFE728';$APIKey = "AIzaSyDeNN1XJBFGE_lJ_35VMUmx5cUbRCUGkjo";$response = sendNotification( $APIKey,array($registrationID),array('message' => $message,'tickerText' => $tickerText,'contentTitle' => $contentTitle,"contentText" => $contentText) );echo $response; ?>
我希望得到类似的东西
{"multicast_ID":6782339717028231855,"success":0,"failure":1,"canonical_IDs":0,"results":[{"error":"InvalIDRegistration"}]}
但我获得(使用两个键)未经授权的401错误.
谢谢您的帮助.
解决方法 而不是输入0.0.0.0作为允许的引用者或允许的IP,不要输入任何内容.这应该工作. 总结以上是内存溢出为你收集整理的android – GCM服务器端PHP – 未经授权的401错误全部内容,希望文章能够帮你解决android – GCM服务器端PHP – 未经授权的401错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)