我沒有找到解決方案,我在我的代碼基礎上找到了其他代碼,我在網絡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時可能會很有用 –