0

ウェブサイトからテキストを取得し、それを Google Cloud のカスタム AutoML Natural Language モデルで実行し、予測データを画面に表示する Chrome 拡張機能を作成しようとしています。

OAuth2 を使用して認証しようとしましたが、許可拒否エラーが発生しました。ドキュメントでは、代わりにサービス アカウントを設定するように指示されています。Chrome 拡張機能をサービス アカウントにする方法はまだわかりませんが、別の Node.JS サーバーをセットアップし、その方法でクエリをリレーする必要があると示唆する人を見つけました。

manifest.js には次のものがあります。

"oauth2": {
    "client_id": "{account_id}.apps.googleusercontent.com",
    "scopes":["https://www.googleapis.com/auth/cloud-platform"]
 }

そして background.js には次のものがあります。

let authToken = '';
chrome.identity.getAuthToken({interactive: true}, function(token) {

    authToken = token;
    fetch("https://automl.googleapis.com/v1beta1/{name}:predict", {

    method: "POST",
    body: `{ 
        "payload": {
            "textSnippet": { 
                "content": "TEXT TO PREDICT GOES HERE", 
                "mime_type": "text/plain"
            }, 
        }  
    }`,
    headers: {
        Authorization: "Bearer " + authToken,
        "Content-Type": "application/json"
    }
    }).then(response => response.text())
    .then(data => console.log(data));
  });

これは、ドキュメントに記載されている curl リクエストをフェッチ リクエストに変換したものです。私は得ています

{
    "error": {
    "code": 403,
    "message": "The caller does not have permission",
    "status": "PERMISSION_DENIED"
    }
}

私の知る限り、アカウントは適切に設定され、Google Cloud 側で権限が付与されています。誰かがここで何が起こっているかを見ていますか?

4

1 に答える 1