第2セット部の冒頭に
と書かれている。 ので、tweetを集めてみようと試みた。 まず、python-twitterモジュールをつかってオープンのツイートを取得してみる。 #! /usr/binh/env python #-*- coding:utf-8 -*- #ref: http://code.google.com/p/python-twitter/ import twitter api = twitter.Api() statuses = api.GetPublicTimeline() print [s.user.name for s in statuses] 実行すると、 Traceback (most recent call last): File "GetTweets2.py", line 6, in <module> statuses = api.GetPublicTimeline() File "/usr/lib/python2.6/site-packages/twitter.py", line 1321, in GetPublicTimeline json = self._FetchUrl(url, parameters=parameters) File "/usr/lib/python2.6/site-packages/twitter.py", line 2032, in _FetchUrl url_data = opener.open(url, encoded_post_data).read() File "/usr/lib64/python2.6/urllib2.py", line 397, in open response = meth(req, response) File "/usr/lib64/python2.6/urllib2.py", line 510, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib64/python2.6/urllib2.py", line 435, in error return self._call_chain(*args) File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain result = func(*args) File "/usr/lib64/python2.6/urllib2.py", line 518, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 404: Not Found とエラーを吐かれる。 によると
まぁ、Twitterさんはあまりpythonのモジュールを更新してくれてないみたいですね。 よって別のモジュールtweepyをつかってみた #! /usr/bin/env python # -*- encode: utf-8 -*- #ref: http://packages.python.org/tweepy/html/getting_started.html import tweepy public_tweets = tweepy.api.public_timeline() for tweets in public_tweets: print tweet.text これも Traceback (most recent call last): File "GetTweets.py", line 6, in <module> public_tweets = tweepy.api.public_timeline() AttributeError: 'API' object has no attribute 'public_timeline' によると とある。 ・・・ ということで、ツイート取得は断念。 別の代用テキストデータにはなにがいいかを思案中。。。ということで |