1

我正在尝试在 Unity 项目中使用 google automl 对象检测。

这是 google curl 命令示例:

curl -X POST \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "Content-Type: application/json" \
  https://automl.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/models/model-id:predict \
  -d '{
        "payload" : {
          "image": {
            "imageBytes" : "/9j/4AAQSkZJRgABAQAAAQ … "
          },
        }
      }'

经过一番谷歌搜索后,我开始创建一个UnityWebRequest测试响应:

WWWForm form = new WWWForm();

        var postUrl = "https://automl.googleapis.com/v1beta1/projects/1043345783500/locations/us-central1/models/IOD1798528344157847552:predict";

        using (UnityWebRequest www = UnityWebRequest.Post(postUrl, form))
        {
            www.SetRequestHeader("Authorization", @"Bearer $(gcloud auth application-default print-access-token)");

            yield return www.SendWebRequest();

            if (www.isNetworkError)
            {
                Debug.Log(www.error);
            }
            else if (www.isDone)
            {
                Debug.Log(www.downloadHandler.text);
            }

        }

所以谷歌的回复是:

{
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

我明白,我不是未经身份验证,但不明白我如何进行身份验证。我必须提出身份验证请求吗?如何?我是否必须发布一些内容才能获得访问令牌?那我应该寄到哪里呢?

我从谷歌服务器下载了一些凭据,但我真的不知道如何使用它......

4

0 回答 0