![](/img/trans.png)
[英]Google Analytics Management Api Insert Goal: 403 Insufficient permission .net
[英]403 permission denied on Google Cloud Datastore .NET client API
使用新的Google Cloud Datastore v1beta客户端库,我得到了
{
"error": {
"errors": [
{
"domain": "global",
"reason": "PERMISSION_DENIED",
"message": "Unauthorized."
}
],
"code": 403,
"message": "Unauthorized."
}
}
对于任何要求。 我创建了一个应用引擎应用,添加了Cloud Datastore API,配置了服务帐户,然后使用它来验证我的请求。
[TestMethod]
public void BasicBlindWrite()
{
var service = new DatastoreService(new BaseClientService.Initializer() { Authenticator = CreateAuthenticator() });
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 = "Consumer", Name = "Consumer-1" });
var firstName = new GoogleData.Property();
firstName.Values = new List<GoogleData.Value>();
firstName.Values.Add(new GoogleData.Value { StringValue = "Samuel"});
entity.Properties = new GoogleData.Entity.PropertiesData();
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, "my-appengine-project-id").Fetch();
}
private OAuth2Authenticator<AssertionFlowClient> CreateAuthenticator()
{
var certificate = new X509Certificate2(TestClientCredentials.ClientCertificateFilePath, "notasecret",
X509KeyStorageFlags.Exportable);
var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
{
ServiceAccountId = TestClientCredentials.CertificateEmailAddress,
Scope = "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/datastore"
};
var authenticator = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);
return authenticator;
}
如果使用Web API控制台,则可以使用。
**更新**
这是我创建服务帐户的方式:
与此问题的答案相同。
为了正确地为您的Cloud Datastore实例配置服务帐户,您必须按照文档中所述使用Cloud Console创建它们。
或者,如果您确实要使用通过[Google API控制台] [3]创建的服务帐户,则可以执行以下操作:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.