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?
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.
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.
The Cloud Natural Language API lets you extract entities from text, perform sentiment and syntactic analysis, and classify text into categories.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With