401 Unauthorized for FCM push notifications on iphone

371 views
Skip to first unread message

Jaydeep Trivedi

unread,
Sep 3, 2018, 10:56:19 AM9/3/18
to Firebase Google Group
*I have followed all the steps mentioned in the documentation and am sending Push notification request to FCM thorugh my server using HTTP v1 API protocol and Google API Client (for php).
* The authentication is done using service-account json downloaded from FCM Console.
* The code is working correctly for Android devices but for some reason it is failing for iphone devices.  For Android the notifications are sent and response code is 200 OK
For my iPad device I am getting 401 unauthorized error.
* Below is my code:
$project_id = '******';//some project id
require_once 'google-api-php-client-2.2.2/vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig(__DIR__ . '/service-account.json');
$client->addScope($scope);
$httpClient = $client->authorize();
$project = "wisdmapp-for-learndash";
//Android device Token
$token = "xxxxxx"; // Some device token
// ipad device token
$token = "xxxxxx"; // Some device token
$message = [
    "message" => [
        "notification" => [
            "body" => "This is an FCM notification message!",
            "title" => "FCM Message",
        ],
        "token" => $token,
    ]
];
$response = $httpClient->post("https://fcm.googleapis.com/v1/projects/{$project}/messages:send", ['json' => $message]);
var_dump($response);

Could you please help me out?
Reply all
Reply to author
Forward
0 new messages