如何在php中获取firebase UserID?

时间:2017-08-17 17:18:02

标签: javascript php firebase firebase-realtime-database algolia

我将通过Algolia文档生成安全API密钥。请参阅文档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文件?

1 个答案:

答案 0 :(得分:1)

首先,需要使用我们的客户端在您的后端生成安全的API密钥。然后,您可以在前端客户端中使用此安全API密钥。

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

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

希望有所帮助!