Home > Software design >  Creates a default database in Firestore using Google.Apis.Appengine.v1 in C# library
Creates a default database in Firestore using Google.Apis.Appengine.v1 in C# library

Time:12-02

I wanted to create cloud firestore database programmatically using c#, but I am getting error when I run the code. How would I fix permission related issue I am facing? Below is the code and error

private static AppengineService _appEngineService;

public static void IntializeAppEngine() {
    GoogleCredential credential = GoogleCredential.GetApplicationDefault();
    if (CloudManager.Credential.IsCreateScopedRequired)
    {
        credential = CloudManager.Credential.CreateScoped(
        AppengineService.Scope.CloudPlatform);
    }

    _appEngineService = new AppengineService(
    new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = CloudManager.ApplicationName
    });

}

public static void AddCloudFirestore() {
    IntializeAppEngine();
    var body = new Application {
        LocationId = "us-east1",
        Id = "projects/"   CloudManager.ProjectId
    };
    
    var res = _appEngineService.Apps.Create(body).Execute();
}

Error:

Unhandled exception. The service appengine has thrown an exception.
HttpStatusCode is Forbidden.
Google.Apis.Requests.RequestError
The caller does not have permission [403]
Errors [
    Message[The caller does not have permission] Location[ - ] Reason[forbidden] Domain[global]
]

Google.GoogleApiException: The service appengine has thrown an exception. HttpStatusCode is Forbidden. The caller does not have permission
   at Google.Apis.Requests.ClientServiceRequest`1.ParseResponse(HttpResponseMessage response)
   at Google.Apis.Requests.ClientServiceRequest`1.Execute()
   at CloudResourceManager.FirebaseManagement.AddCloudFirestore()

CodePudding user response:

Instead of Appengine, Cloud Firestore REST API can be used as Sarah suggested. In c# Google.Apis.Firestore.v1 can be used to create cloud firestore.

  • Related