Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parameters for google cloud natural language api

I want to use pure http requests to get the result from google cloud natural language api, but their document does not specify the parameter names.

Here is my python code:

import requests
url = "https://language.googleapis.com/v1beta1/documents:analyzeEntities"
d = {"document": {"content": "some text here", "type": "PLAIN_TEXT"}}
para = {"key": "my api key"}
r = requests.post(url, params=para, data=d)

Here is the error message: {u'error': {u'status': u'INVALID_ARGUMENT', u'message': u'Invalid JSON payload received. Unknown name "document": Cannot bind query parameter. \'document\' is a message type. Parameters can only be bound to primitive types.', u'code': 400, u'details': [{u'fieldViolations': [{u'description': u'Invalid JSON payload received. Unknown name "document": Cannot bind query parameter. \'document\' is a message type. Parameters can only be bound to primitive types.'}], u'@type': u'type.googleapis.com/google.rpc.BadRequest'}]}}

how should I create the http request without using their python library?

like image 615
al3xtouch Avatar asked Oct 13 '16 06:10

al3xtouch


People also ask

How does Google NLP API work?

The tool uses machine learning to reveal the structure and the meaning of the text. You can see which information about people, places, and events Google extracts and considers relevant, so you can use these insights to craft content that Google will easily understand and get you closer to the target reader.

What is Google Cloud natural language API?

The Natural Language API provides a powerful set of tools for analyzing and parsing text through syntactic analysis. To perform syntactic analysis, use the analyzeSyntax method. Syntactic Analysis consists of the following operations: Sentence extraction breaks up the stream of text into a series of sentences.

What type of actions can be done by cloud Natural Language API?

The Cloud Natural Language API lets you extract entities from text, perform sentiment and syntactic analysis, and classify text into categories.


1 Answers

ok, I figured it out. I need to pass JSON-Encoded POST/PATCH data, so the request should be r = requests.post(url, params=para, json=d)

like image 139
al3xtouch Avatar answered Oct 14 '22 08:10

al3xtouch