0

I'm trying to use twitter-python to connect to twitter's API, and I keep getting this pesky 404 error!

Code is below:

import sys
import twitter
def main():
  api = twitter.Api()
  statuses = api.GetPublicTimeline()
  print [s.user.name for s in statuses]

It should come back with the names of people who've posted status updates on the public timeline, but I get this traceback instead.

Traceback (most recent call last):
  File "new.py", line 14, in <module>
    main()
  File "new.py", line 10, in main
    statuses = api.GetPublicTimeline()
  File "/usr/lib/pymodules/python2.7/twitter.py", line 1319, in GetPublicTimeline
    json = self._FetchUrl(url,  parameters=parameters)
  File "/usr/lib/pymodules/python2.7/twitter.py", line 2030, in _FetchUrl
    url_data = opener.open(url, encoded_post_data).read()
  File "/usr/lib/python2.7/urllib2.py", line 400, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 513, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 438, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 372, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 521, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found

If I try to authenticate, all of my requests come back as 401.

Thanks for your help!

4

2 に答える 2

0

開発者が oAuth プロセスを簡単に行えるようにするという点では、Twitter は優れた API の 1 つです。Twitter にログインしてhttps://dev.twitter.com/appsの開発者ダッシュボードにアクセスすると、新しいアプリケーションを登録 (または既存のアプリケーションを構成) できます。

アプリケーションの詳細を表示すると、「oAuth ツール」タブが表示され、そのアプリに関連するすべての oAuth 値 (コンシューマー キー、コンシューマー シークレット、アクセス トークン、およびアクセス トークン シークレット) が表示されます。

Twitter で常に同じユーザーとして認証されるアプリケーションを作成している場合は、これらの値をコードにハードコードするか、構成ファイルのどこかに保存するだけです。アプリケーションが複数のユーザーに代わって Twitter で認証する必要がある場合 (たとえば、ユーザーに代わってステータスを投稿できるようにするため)、https://dev. twitter.com/docs/auth/3-legged-authorization .

于 2013-01-31T22:57:59.603 に答える