在React-Native中使用Google Cloud AutoML视觉模型

问题描述 投票:0回答:1

我将使用经过训练的Google Cloud AutoML视觉模型来检测对象并在React-Native中获取坐标。我已经训练了模型,但是我应该使用令牌来调用训练后的模型。我可以使用gcloud auth application-default print-access-token生成令牌但是我认为令牌将过期,用户无法调用此API。什么是解决此问题的最佳方法?

fetch(
      'https://automl.googleapis.com/v1/projects/(projectid)/locations/(locationid)/models/(modelID):predict',
      {
        method: 'POST',
        headers: {
          Authorization:
            'Bearer (bearer token)',
          'Content-Type': 'application/json',
        },
        contentType: 'application/json',
        body: JSON.stringify({
          payload: {
            image: {
              imageBytes: base64Image.base64,
            },
          },
        }),
      },
    )

这是我的本机代码。谢谢您的回答。

react-native google-cloud-platform oauth-2.0 google-cloud-automl automl
1个回答
0
投票

通常,您要验证with a service account。这样,您就可以下载一个key.json文件,如果您单击export GOOGLE_APPLICATION_CREDENTIALS=path_to_your_key_file.json,程序将可以访问该文件。另外,如果您不想在客户端上保留密钥文件,则可以创建一个与Vision API对话的REST端点(例如,使用Google Cloud Function或Firebase Function),该端点可以处理例如速率限制。然后,您的React Native应用程序将直接到达包装REST端点,而不是Vision API。

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