为什么我使用 google api 客户端获得的 oauth 访问令牌包含大量“...”

why does my oauth access token obtained using google api client contains plenty of '...'

我正在使用 PHP 获取 FCM 的 oauth 令牌,但是返回的访问令牌包含很多“....”

$client= new \Google_Client();
    error_log(__DIR__);
    $client->setAuthConfig(__DIR__ . '/service-account-key.json');
    $client->addScope('https://www.googleapis.com/auth/firebase.messaging');
    $client->refreshTokenWithAssertion();
    $token = $client->getAccessToken();

    error_log(json_encode($token));
    return $token;

结果

实际访问令牌不包含星号(*),它曾经是我用星号替换的字符以审查令牌。

{"access_token":"ya29.*.b*************r1FYWFz***CCg3v8VYHTlu*******************hiMIDhSX******6UfwvazfOcuV***********ewuo-c87WgM-ir
S5unipu0goCl3RtC_0g7hkjqNwQ2pcZjmJCZIr7JM5VwD4........................................................................................................................................................................................
......................................................................................................................................................................................................................................
......................................................................................................................................................................................................................................
....................................................................................................................................................","expires_in":3599,"token_type":"Bearer","created":1652776589}

谁能告诉我为什么它会返回一堆“.”

尽管返回的访问令牌是填充句点 (...),但使用该访问令牌发送 FCM 通知没有问题。阻止我发送通知的问题是由于没有按照正确的有效负载格式发送数据。

理想的负载格式

$data = array(
                "message" => array(
                    "token" => $user->device_token,
                    "notification" => array(
                        "title" => "New Task",
                        "body" => "Hi " . $user->name . ",\nYou have a new " . $ticket_description ." task to work on.",
                    ),
                    "data" => array(
                        "notification_id" => $notificationMessage->id,
                        "item_id" => $notificationMessage->item_id,
                        "ticket_classification" =>   $notificationMessage->classification,
                        "ticket_segment_type" => $notificationMessage->segment_type,
                        "routing_page"=>$notificationMessage->page_routing_classification,
                        "title" => $notificationMessage->title ,
                        "body" => $notificationMessage->body ,
                    ),

                    "android" => array(
                        "priority" => "high",
                        "notification" => array(
                            "sound" => 'default',
                            //So that noptification can be sent while the app is killed
                            "click_action" => "FCM_PLUGIN_ACTIVITY",
                        )
                    )
                )
            );