I'm sending a downstream message to a single device from app server via Firebase server. I'm using the devices reg token that was passed to the apps server. app server code is
$firebase_token = $request->input('token');
$skey = env('FCM_SERVER_KEY');
$client = new Client(['verify' => false]);
$response = $client->request('POST', 'https://fcm.googleapis.com/fcm/send', [
'headers' => [
'Authorization:key=' => $skey,
'Content-Type' => 'application/json'
],
'json' => ['to' => $firebase_token, 'data' => ['message' => 'This is Genius']]
]);
I'm receiving the following message from my android app (cause i'm testing out FCM and i'm sending the $response
back to my app on the emulator.) Its the same message I'm getting on Postman.
{"message":
"Server error: `POST https:\/\/fcm.googleapis.com\/fcm\/send` resulted in a
`500 Internal Server Error` response:\n
<HTML>\n
<HEAD>\n
<TITLE>Internal Server Error<\/TITLE>\n
<\/HEAD>\n
<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n
<H1>Internal ServerE(truncated...)\n",
"code":500,
"status_code":500,"debug"
...
I'm using Laravel and Guzzle Client to deliver the message to the FCM server, I tried sending a message to my emulator from my Firebase console and it marked the message as completed but I didn't receive it on my app/emualtor. This is my onMessageReceived
method inside my FirebaseMessagingService
class
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
showNotification(remoteMessage.getData().get("message"));
}
private void showNotification(String message) {
Intent i = new Intent(this,MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("FCM Test")
.setContentText(message)
.setSmallIcon(R.drawable.com_facebook_button_send_icon_blue)
.setContentIntent(pendingIntent);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(0,builder.build());
}
I'm not sure whats wrong with my setup. Any help will be appreciated.
确保您的凭据正确,因为互联网连接问题,可能无法接收到模拟器
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.