C# 连接到Google云数据存储时出错

C# 连接到Google云数据存储时出错,c#,google-cloud-datastore,C#,Google Cloud Datastore,我尝试使用.NET驱动程序beta1在Google云数据存储中插入一个实体。代码如下: String serviceAccountEmail = "***.apps.googleusercontent.com"; var certificate = new X509Certificate2( @"***-privatekey.p12", "notasecret", X509KeyStorageFlags.Exportable); ServiceAccountCredential cr

我尝试使用.NET驱动程序beta1在Google云数据存储中插入一个实体。代码如下:

String serviceAccountEmail = "***.apps.googleusercontent.com";

var certificate = new X509Certificate2(
    @"***-privatekey.p12", "notasecret", X509KeyStorageFlags.Exportable);

ServiceAccountCredential credential = new ServiceAccountCredential(
   new ServiceAccountCredential.Initializer(serviceAccountEmail) {
       Scopes = new[] {
           Google.Apis.Datastore.v1beta1.DatastoreService.Scope.Datastore.ToString().ToLower()
       }
   }.FromCertificate(certificate));

// Create the service.
var service = new DatastoreService(new BaseClientService.Initializer() {
    HttpClientInitializer = credential,
    ApplicationName = "***",
});

var request = new GoogleData.BlindWriteRequest();
var entity = new GoogleData.Entity();
entity.Key = new GoogleData.Key();
entity.Key.Path = new List<KeyPathElement>();
entity.Key.Path.Add(new GoogleData.KeyPathElement { Kind = "KindTest", Name = "name" });
var firstName = new GoogleData.Property();
firstName.Values = new List<GoogleData.Value>();
firstName.Values.Add(new GoogleData.Value { StringValue = "FName" });
entity.Properties = new Dictionary<string, Property>();

entity.Properties.Add("FirstName", firstName);
request.Mutation = new GoogleData.Mutation();
request.Mutation.Upsert = new List<GoogleData.Entity>();
request.Mutation.Upsert.Add(entity);

var response = service.Datasets.BlindWrite(request, "***").Execute();

有人知道如何解决这个问题吗?

我相信您需要
userinfo.email
范围:

https://www.googleapis.com/auth/userinfo.email

另外-确保已启用云数据存储API(请参阅)。

您是否设法从
凭证
获取有效的访问令牌?(还要注意,您还需要userinfo范围)。
https://www.googleapis.com/auth/userinfo.email