gpt4 book ai didi

javascript - 如何在 php 中获取 firebase UserID?

转载 作者:行者123 更新时间:2023-11-30 21:15:17 25 4
gpt4 key购买 nike

我正在浏览 Algolia 文档以生成安全 API key 。请参阅文档 https://www.algolia.com/doc/tutorials/security/api-keys/secured-api-keys/how-to-restrict-the-search-to-a-subset-of-records-belonging-to-a-specific-user/ .

我正在使用 javascript,但文档将下面的代码列为 php 文件。

   $index->setSettings([
'attributesForFaceting' => [
'filterOnly(viewable_by)'
]
]);

还有这个

   $index->partialUpdateObject(
[
'viewableBy' => [1, 2],
'objectID' => 'myID1'
]
);

然后是这个

  $currentUserID = 1; // Replace by the current user ID

$securedApiKey = $client->generateSecuredApiKey(
'YourSearchOnlyApiKey', // Make sure to use a search key
[
'filters' => 'viewable_by:'.$currentUserID
]
);

首先我知道 firebase.auth().currentUser.uid 用于在 javascript 中获取 firebase 用户 ID,我如何在 PhP 中获取“currentUserID”以及如何将我的 php 文件连接到我的 JS 文件?

最佳答案

首先,需要使用我们的一个客户端在您的后端生成安全的 API key 。然后,您可以在前端客户端中使用这个安全的 API key 。

在您提供的链接中,后端客户端使用 PHP,但您可以改用 JS。你可以在这里找到一个更好的例子:

https://www.algolia.com/doc/api-client/javascript/api-keys/#generate-key

希望对您有所帮助!

关于javascript - 如何在 php 中获取 firebase UserID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45741373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com