C# 如何通过HTTP请求验证Google Cloud Vision
我正在尝试使用c#通过rest http请求使用Google Cloud Vision。如上所述,我尝试使用api密钥作为参数进行身份验证:C# 如何通过HTTP请求验证Google Cloud Vision,c#,rest,authentication,google-cloud-platform,google-cloud-vision,C#,Rest,Authentication,Google Cloud Platform,Google Cloud Vision,我正在尝试使用c#通过rest http请求使用Google Cloud Vision。如上所述,我尝试使用api密钥作为参数进行身份验证: string uri = "https://vision.googleapis.com/v1/images:annotate?key=" + API_KEY; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri); [...] response = await c
string uri = "https://vision.googleapis.com/v1/images:annotate?key=" + API_KEY;
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri);
[...]
response = await client.SendAsync(request);
但是,我总是收到403权限拒绝代码:
Cloud Vision API以前未在项目XXXXX中使用过,或者是
残废通过访问来启用它
然后重试。如果您最近启用了此API,请等待几分钟
要传播到系统并重试的操作
当然我已经检查过了,API已经激活,启用,并且没有API限制:
由于该身份验证方法似乎存在漏洞,特别是在CloudVision中,我尝试通过我创建的服务帐户的访问令牌进行身份验证。我授予服务帐户完全访问权限只是为了确保服务帐户的权限没有问题:
string uri = "https://vision.googleapis.com/v1/images:annotate";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri);
request.Headers.Add("Authorization", "Bearer " + ACCESS_TOKEN);
response = await client.SendAsync(request);
不过,还是有相同的错误消息。卷曲也是如此:
curl -k -X POST -H "Content-Type:application/json"
-d "@{REQUEST_AS_JSON_OR_PATH_TO_JSON-FILE}"
https://vision.googleapis.com/v1/images:annotate?key={API_KEY}
我遗漏了什么?原来激活API密钥是不够的(即使它没有任何限制),但需要主动进入菜单->API和服务->库->搜索“Cloud Vision”->点击Cloud Vision API并激活它。这需要几分钟。此操作的状态不会显示在仪表板中 然后,您可以简单地使用api密钥作为URL参数进行身份验证