Google Firestore请求的身份验证范围不足

时间:2018-12-05 14:13:26

标签: php firebase google-cloud-firestore

我正在关注官方firestore quick start tutorial,这是我的代码-

use Google\Cloud\Firestore\FirestoreClient;
require 'vendor/autoload.php';
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);


initialize();



function initialize()
{
    // Create the Cloud Firestore client
    $db = new FirestoreClient();
    printf('Created Cloud Firestore client with default project ID.' . PHP_EOL);
    $docRef = $db->collection('users')->document('lovelace');
    $docRef->set([
        'first' => 'Ada',
        'last' => 'Lovelace',
        'born' => 1815
    ]);
    printf('Added data to the lovelace document in the users collection.' . PHP_EOL);

}

我收到此错误消息Uncaught Google \ Cloud \ Core \ Exception \ ServiceException:{“ message”:“请求的身份验证范围不足。”,“ code”:7,“ status”:“ PERMISSION_DENIED”,< / p>

我的数据库规则是

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}

1 个答案:

答案 0 :(得分:0)

您应按以下方式调整规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

但是请注意,使用这些规则可以“允许在任何情况下对所有用户进行读/写访问”。强烈建议在生产时进行更改,请参见https://firebase.google.com/docs/firestore/security/get-started

相关问题