I'm trying to write a Chrome extension that takes the text from a website and runs it through a custom AutoML Natural Language model on Google Cloud and then displays the prediction data to the screen.
I've tried authenticating using OAuth2, which is giving me Permission denied errors, and the documentation is saying to set up a service account instead. I haven't figured out how to make the chrome extension into a service account, but I've found people suggesting that I will have to set up a separate Node.JS server and relay the queries that way.
In manifest.js I have:
"oauth2": {
"client_id": "{account_id}.apps.googleusercontent.com",
"scopes":["https://www.googleapis.com/auth/cloud-platform"]
}
and in background.js I have:
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));
});
This is a translation of the curl request described in the documentation turned into a fetch request. I'm getting
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}
As far as I can tell, the account is properly set up and given the permissions on the Google Cloud side. Does anyone see what's going on here?