之前尚未在项目618104708054中使用Cloud AutoML API或将其禁用

时间:2018-08-31 14:01:07

标签: automl google-cloud-automl

我正在尝试使用在AutoML上试用过的模型来构建.NET小型应用程序,以预测图像。

但是我收到此错误:

  

项目618104708054之前或之前未使用Cloud AutoML API   它被禁用。通过访问启用它   https://console.developers.google.com/apis/api/automl.googleapis.com/overview?project=618104708054   然后重试。如果您最近启用了此API,请等待几分钟   传播到我们的系统并重试的操作

首先-这不是我正在使用的项目。 其次-如果我转到带有真实项目ID的链接-它告诉我api运行良好。

我的代码如下:

public static string SendPOST(string url, string json)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";
            httpWebRequest.Headers.Add("Authorization", "Bearer GOOGLE_CLOUD_TOKEN");
            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                //var res = new JavaScriptSerializer().Deserialize<Response>(result);
                //return res;
                return result;
            }           
        }

我会尽力帮助您, 谢谢。

1 个答案:

答案 0 :(得分:1)

我终于成功实现了,唯一的问题是我需要使用Web控制台创建服务帐户:

https://console.cloud.google.com/projectselector/iam-admin/serviceaccounts?supportedpurview=project&project=&folder=&organizationId=

然后下载json密钥并通过gcloud命令从我的PC推送它-

gcloud auth activate-service-account --key-file="[/PATH/TO/KEY/FILE.json]

我在这篇文章中找到了解决方案: "(403) Forbidden" when trying to send an image to my custom AutoML model via the REST API

相关问题