我没有找到解决方案,我在我的代码基础上找到了其他代码,我在网络http://zakilive.com/tag/google-cloud-messaging-php-tutorial/中找到了,因为Google不存在样品为PHP,我有下一个代码:我在Google Cloud Natural Language API中遇到了这个错误:The AnnotateTextRequest.features在PHP中为空
<?php
define("API_ACCESS_KEY", "my api key");
$msg = array
(
\t 'document' \t => array(
\t
\t \t 'type'=>'PLAIN_TEXT',
\t \t 'content'=>"Michelangelo Caravaggio, Italian painter, is known for
'The Calling of Saint Matthew'."
\t
\t),
\t 'encodingType'=>'UTF8',
);
$headers = array
(
\t 'Authorization: Bearer ' . API_ACCESS_KEY,
\t 'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'https://language.googleapis.com/v1beta1/documents:annotateText');
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($msg));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
完全缓解是: { “错误”:{ “代码”:400, “消息”:“的AnnotateTextRequest.features是空的。“,”状态“:”INVALID_ARGUMENT“,”详情“:[{”@type“:”type.googleapis.com/google.rpc.Ba dRequest“,”fieldViolations“:[{”field“:”AnnotateTextRequest.features“,”description“:”没有指定的功能。“ }]}]}}
我仍然无法在其他语言的代码。
帮助我,请
的API是:https://cloud.google.com/natural-language/docs/
你让它工作。我总是收到这个错误“请求无法用客户端项目识别,请传递一个有效的API密钥和请求。” –
FYI [此项目](https://github.com/darrynten/google-natural-language-php)在使用此API时可能会很有用 –