Firebase FCM: invalid-argument

后端 未结 2 1831
天命终不由人
天命终不由人 2021-01-14 16:57

I\'m trying FCM for the first time, so just using their sample code. In fact I\'m even sending their sample messages. The following code, which is straight from the document

2条回答
  •  北海茫月
    2021-01-14 17:09

    I had " in my strings in my json, I changed it to ' and it fixed the problem!

    $response = $client->post(
                'https://fcm.googleapis.com/v1/projects/xxx/messages:send',[
                'headers' => [
                    'Content-Type' => 'application/json',
                    'Authorization'     => 'Bearer ' . $token['access_token'],
                ],
                GuzzleHttp\RequestOptions::JSON => [
                    "message" => [
                        "token"  => "dflhjldkjhflksfshklsf",
                        "notification" => [
                            "title" => "FCM Message",
                            "body" => "This is an FCM notification message!"
                        ]
                    ]
                ]
            ]);
    

    to:

    $response = $client->post(
                    'https://fcm.googleapis.com/v1/projects/xxx/messages:send',[
                    'headers' => [
                        'Content-Type' => 'application/json',
                        'Authorization'     => 'Bearer ' . $token['access_token'],
                    ],
                    GuzzleHttp\RequestOptions::JSON => [
                        'message' => [
                            'token'  => 'dflhjldkjhflksfshklsf',
                            'notification' => [
                                'title' => 'FCM Message',
                                'body' => 'This is an FCM notification message!'
                            ]
                        ]
                    ]
                ]);
    

    Hope it helps!

提交回复
热议问题