2
votes

I do not found solution, I do my code in base to other code that I found in the web http://zakilive.com/tag/google-cloud-messaging-php-tutorial/ , because in Google not exist sample for php, I have the next Code:

<?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;

The complete response is: { "error": { "code": 400, "message": "The AnnotateTextRequest.features is empty.", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [ { "field": "AnnotateTextRequest.features", "description": "No features specified." } ] } ] } }

I could not do the code in other language still.

Help me please

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

1

1 Answers

2
votes

I fix my code, I lacked the "features" and I see in the page: https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText and in https://cloud.google.com/natural-language/reference/rest/v1beta1/documents/annotateText#Features and I pub in my code in the $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',
	
);

and now I have a good response, but now my ask is how can I do for generate a API_ACCESS_KEY automaticaly, but I guess that this is other question.