0

I get errors when posting prediction requests, but when posting the same requests from the online interface (from Google's API reference page) works well. I have also posted a new issue on the Git repository, but it seems that no-one even looks at these issues. How lame of Google !!

Well I am posting predict request, which look like this:

var parameters = {
auth: jwtClient,
project: googleProjectID,
id: 'interest_classifier',
input: {
csvInstance: ["country united states", "/location/location"]
}
};
return prediction.trainedmodels.predict(parameters, function(err, response) {
if (err) {
logger.info(null, "prediction err ", err);
}
logger.info(null, "response from predict ", response);
return callback(null, response);
});

And I get this:

err { [Error: Input data invalid.]
code: 400,
errors:
[ { domain: 'global',
reason: 'invalidValue',
message: 'Input data invalid.' } ] }

To clarify: my trained model contains a value and two textual features. Again, when running this from the online tool (client side) it works well, only when I run it from my node.js server, does it fail.

What's up with that? Anyone knows? Could this be some encoding issue? request headers?

EDIT:

this is how i authenticate :

var   jwtClient = new google.auth.JWT('*****@developer.gserviceaccount.com', 'keys/key.pem', null, ['https://www.googleapis.com/auth/prediction']);

  jwtClient.authorize(function(err, tokens) {
    logger.info(null, "authorizing");
    if (err) {
      logger.info(null, "error ", err);
    } else {
      return logger.info(null, "authenticated ", tokens);
    }
  });
4

1 回答 1

0

好的,

所以我深入研究了谷歌的代码,发现了一个没有正确记录的重要细节。

我认为这可能与使用该库的其他人有关,而不仅仅是使用 google predict 的人。

所以大多数请求都需要在参数中包含项目 ID,但在某些情况下,您还需要包含发布数据(如我的情况)。我试图将这个帖子数据直接包含在参数中,如下所示:

var parameters = {
auth: jwtClient,
project: googleProjectID,
id: 'interest_classifier',
input: {
csvInstance: ["country united states", "/location/location"]
}
};

现在我发现(这没有记录!!)属于帖子数据的整个部分应该包含在“资源”字段中,如下所示:

var parameters = {
auth: jwtClient,
project: googleProjectID,
id: 'interest_classifier',
resource:{
input: {
csvInstance: ["country united states", "/location/location"]
}
}
};

我相信这将与任何包含发布数据的请求相关。干杯,宜兰

于 2015-05-29T20:53:26.667 回答