大佬教程收集整理的这篇文章主要介绍了android – GCM服务器端PHP – 未经授权的401错误,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在凭证方面,我创建了在引用中键入0.0.0.0的浏览器API密钥.实际上我创建了两种类型的键,因为我在不同的教程中找到了不同的指示.
<? /** * 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错误.
谢谢您的帮助.
以上是大佬教程为你收集整理的android – GCM服务器端PHP – 未经授权的401错误全部内容,希望文章能够帮你解决android – GCM服务器端PHP – 未经授权的401错误所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。