2016-07-29 7 views
0

私は解決策が見つかりませんでした.Googleに存在しないため、http://zakilive.com/tag/google-cloud-messaging-php-tutorial/Google Cloud Natural Language APIでこのエラーが発生しました:PHPでAnnotateTextRequest.featuresが空です

<?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 PHPのサンプル、私は次のコードを持っています空 "、"ステータス ":" INVALID_ARGUMENT "、"詳細 ":[{" @type ":" type.googleapis.com/google.rpc.Ba dRequest "、" fieldViolations ":[{" field ":" AnnotateTextRequest.features "、" description ":"機能が指定されていません " }]}]}}

他の言語でもコードを実行できませんでした。

APIである私を助けてください:https://cloud.google.com/natural-language/docs/

答えて

1

私は自分のコードを修正し、私は「機能」を欠いていたと私はページに表示:https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateTexthttps://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText#Featuresにし、私は私のコードパブ$ msgあるVAR:

$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 'features'=>array(
 
\t "extractSyntax"=> true, 
 
    "extractEntities"=> false, 
 
    "extractDocumentSentiment"=> false 
 
\t), 
 
\t 'encodingType'=>'UTF8', 
 
\t 
 
);

、今I H良い回答が得られましたが、今私の質問は、API_ACCESS_KEY自動生成のためにどうすればよいのでしょうか?これは他の質問だと思います。

+0

あなたはそれを働かせてください。私はいつもこのエラーを受け取っています」リクエストはクライアントプロジェクトでは特定できません。リクエストに有効なAPIキーを渡してください。 –

+0

FYI [このプロジェクト](https://github.com/darrynten/google-natural-language-php)は、このAPIを使用する際に役立つ場合があります –

関連する問題