如何在Unity中通过Google Cloud进行身份验证?

问题描述 投票:0回答: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);
            }

        }

所以Google的回复是:

{
  "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"
  }
}

我知道,我不是未经身份验证的,但不明白如何进行身份验证。我必须提出认证请求吗?怎么样?我必须发布一些东西以获得访问令牌吗?那我应该寄到哪里呢?

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

unity3d google-oauth google-cloud-automl
1个回答
0
投票

@ dreamend。您找到身份验证的解决方案了吗?我可以从cmd提示符下获取accesstoken,并统一使用它可以正常工作。您如何统一进行身份验证。

© www.soinside.com 2019 - 2024. All rights reserved.