See this [article] by Anchibe-san (http://antibayesian.hateblo.jp/entry/20110828/1314491180), ・ Python3 (3.5.1) ・ Windows 10 (64bits) -Install python with anaconda I tried to do the same in my environment.
See additional: ・ Http://www.slideshare.net/pika_shi/pythontwittertwitter -Htp: // d. Hatena. Right. jp / Hangyo 22/20120430/1335786712 ・ Http://blog.kzfmix.com/entry/1206780815 Thanks to everyone who publishes useful information online.
For the time being, when I went to the point of drawing a graph on 2016/06/11, the version I am using is 3.1. Since I am stuck with API restrictions, I changed the source of 3.1 and used it.
For the basics, please refer to Anchibe's page. Below are some minor changes.
api = twitter.Api(consumer_key='***', #your_consumer_key,
consumer_secret='***', #your_consumer_secret,
access_token_key='***', #your_access_token_key,
access_token_secret='***', #your_access_token_secret,
input_encoding = "utf-8",
sleep_on_rate_limit=True)
Since I installed it with anaconda, I wanted to do it with conda, but I could not install the latest version 3.0rc1 of python-twitter as of 2016/05 (it seems that changes have been made to support Python v3), so Use pip.
pip install python-twitter==3.0rc1
⇒ As of May 28, 2016, the latest version is 3.1, so
It will be pip install python-twitter == 3.1
.
pip install python-twitter == 4.0
. I am confirming with the message displayed by.conda list
A list of packages installed in is displayed, so check that python-twitter is installed.
When the version of python-twitter was 3.0rc1, an error occurred when there was input_encording ='utf-8' in twitter.Api (), but it was resolved when the version became 3.1.
GetFriends seems to be an operation that collects information on everyone, not just 100 people. If you don't need a lot of information to check the operation of the source, you can set the upper limit with'total_count ='in twitter.Api ().
Also, there is a setting such as timeout = (default 60 seconds)
, so it may be better to review the setting if the line is unstable. * I'm not sure.
As a result, graph drawing is completed. Next, derive meaningful results from the graph. This is not yet.
twitter.error.TwitterError: [{'message': 'Rate limit exceeded', 'code': 88}]
Came out. As a response, even if I tried to set sleep_on_rate_limit = True, it was displayed in python-twitter == 3.0rc1 that it was an error in __init__
, but as of May 28, 2016, the latest, 3.1 shows an error It is no longer done. Therefore solved.
In the calculation of the number of seconds to sleep in time.sleep in _RequestUrl () of Python-twitter, it is truncated after the decimal point by int (), so I added the surplus number here and checked the operation, but only here It doesn't seem to matter much because you can't avoid getting stuck in API call restrictions by changing.
The final change to avoid API restrictions was to change some of the python-twitter source. Changed the process that sleeps when the API remaining number is just 0 to sleep when the API remaining number is 2 or less.
So far, I can draw a graph, but I can't find any meaning in the result. There are various possible reasons for this, such as whether you are following too many people in various fields, or whether you need to devise an algorithm for drawing network graphs, but it is unknown at this time. We will continue to confirm.
-Edit python-twitter api.py. -(This may not work) time.sleep (int (...) + seconds) -Only when API remaining == 0, change the condition of the if statement to sleep, for example, to sleep at 2 or less.
https://github.com/bear/python-twitter/issues/350
Recommended Posts