我在Google Cloud自然语言API中有这样的错误:AnnotateTextRequest.features在PH


I have this error with Google Cloud Natural Language API: The AnnotateTextRequest.features is empty in PHP

我没有找到解决方案,我在库中对在web中找到的其他代码执行代码http://zakilive.com/tag/google-cloud-messaging-php-tutorial/,因为在Google中不存在php的示例,我有下一个代码:

<?php
define( "API_ACCESS_KEY", "my api key" );
$msg = array
(
	'document' 	=> array(
	
		'type'=>'PLAIN_TEXT',
		'content'=>"Michelangelo Caravaggio, Italian painter, is known for
              'The Calling of Saint Matthew'."
	
	),
	'encodingType'=>'UTF8',
);
$headers = array
(
	'Authorization: Bearer ' . API_ACCESS_KEY,
	'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;

完整的回复是:{"error":{"code":400,"message":"AnnotateTextRequest.features为空。","status":"INVALID_ARGUMENT","details":[{"@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"field":"AnnotateTextRequest.features","description":"未指定任何功能。"}]}}

我仍然无法用其他语言编写代码。

请帮帮我

API是:https://cloud.google.com/natural-language/docs/

我修复了我的代码,我缺少"功能",我在页面中看到:https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText和https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText#Features我在$msg-var:中发布我的代码

$msg = array
(
	'document' 	=> array(
	
		'type'=>'PLAIN_TEXT',
		'content'=>"Michelangelo Caravaggio, Italian painter, is known for
              'The Calling of Saint Matthew'."
	
	),
	'features'=>array(
	"extractSyntax"=> true,
  "extractEntities"=> false,
  "extractDocumentSentiment"=> false
	),
	'encodingType'=>'UTF8',
	
);

现在我得到了很好的回答,但现在我的问题是如何自动生成API_ACCESS_KEY,但我想这是另一个问题。