我想发送推送通知,但是当代码执行时,它显示无效的注册错误。下面是代码如何在android中获取有效的firebase令牌?
LoginActivity
String getToken = FirebaseInstanceIDService.onTokenRefreshs();
String getUsername = username.getText().toString();
String URL = DataHolder.TokenUrl(getUsername,getToken);
OnTokenRefresh
代码
public class FirebaseInstanceIDService extends FirebaseInstanceIdService {
public static String onTokenRefreshs(){
String token = FirebaseInstanceId.getInstance().getToken();
return token;
}
}
pushnotification代码
$url = 'https://fcm.googleapis.com/fcm/send';
$message = array("message" => "hell man");
$xyz=array("firebasetokengoeshere I haven't included for now");
$fields = array(
'to' => json_encode($xyz),
'data' => $message
);
$headers = array(
'Authorization:key = Appkey goes here',
'Content-type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if($result === FALSE){
}
curl_close($ch);
return $result;
$message_status = send_notification($tokens, $message);
echo $message;
{ “multicast_id”:6744250798651355841, “成功”:0,”失败 “:1,” canonical_ids “:0”,结果 “:[{” ERR或“:”InvalidRegistration“}]}
我得到了上述结果。如何解决这个错误。