Cloud AutoML API 之前未在项目 618104708054 中使用过或已禁用

Cloud AutoML API has not been used in project 618104708054 before or it is disabled

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

但是我收到这个错误:

Cloud AutoML API has not been used in project 618104708054 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/automl.googleapis.com/overview?project=618104708054 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry

首先-这不是我正在使用的项目。 其次 - 如果我使用我的真实项目 ID 访问 link - 它告诉我 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;
            }           
        }

我会感谢你的帮助, 谢谢

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

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

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

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

我在这个 post 中找到了解决方案: