为什么使用Google API客户端获得的我的OAuth访问令牌包含大量' ...'

发布于 2025-01-29 18:23:02 字数 1584 浏览 4 评论 0原文

我正在使用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}

有人可以告诉我为什么它会返回一堆“”。

I am using PHP to get oauth token for FCM however the access token returned contains a lot of '....'

$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;

Result

The actual access token doesnt contain the asterisk(*), it used to be characters that i have replaced with asterisks to censor out the token.

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

Can someone please tell me why it is returning a bunch of '.'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安静 2025-02-05 18:23:02

尽管返回的访问令牌是填充期(...),但使用该访问令牌发送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",
                        )
                    )
                )
            );

Despite the access token being returned is filled periods(...), there is no issue using that access token to send a FCM notification. The issue that prevent me from sending a notification out is due to not following the correct payload format to send out the data.

Ideal payload format

$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",
                        )
                    )
                )
            );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文