If I want to do an analysis of a single Twitter user with 1000 tweets, do I have to make 1000 API calls to the Watson Personality Insights API?

邮差的信 提交于 2019-12-11 09:59:27

问题


I want to use the Watson Personality Insights API to analyze the personality traits of a particular Twitter user. This user has 1000 tweets. Do I have to call the Personality Insights API 1000 times in order to do this?


回答1:


Personality Insights can process multiple text elements in a single API call. To obtain a single result (the a meaningful output according to the service documentation) this needs to be written by an individual author.

Now assuming you obtained 1000s of tweets from an author, you can format them in one (big) JSON string and POST-it with Content-Type: application/json header in your request. See the specs (right under "JSON output for text with timestamps" title) for an example of this type of input, with multiple elements included.

How many elements can fit in a single request? Currently the APIs limit the input payload to 20Mb. If you count the characters used by each of the contentItems in the JSON above, and assuming a 140-character limit per tweet, this gives about 350 characters used per tweet. So you can fit about 57,000 tweets in a single API call! At least, if this is English text (or rather: ASCII encoded text); the object size might perhaps double with utf-8 encoding special characters, but that will still leave plenty of room for many thousands of tweets.




回答2:


No you don't. You DO need to "bundle" the 1000 tweets in JSON and submit them with your SINGLE call to the profile method of the Personality Insights API. These tweets are each contained as individual content items in the JSON.

For details on the format of the JSON payload, and the response format, see the online documentation at http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/personality-insights/api/v2/?node#methods



来源:https://stackoverflow.com/questions/33882395/if-i-want-to-do-an-analysis-of-a-single-twitter-user-with-1000-tweets-do-i-have

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!