Reputation: 53
I install Tweepy and Python-Twitter and try basic code
import twitter
api = twitter.Api(consumer_key=["X"],
consumer_secret=["X"],
access_token_key=["35X-X"],
access_token_secret=["X"])
print(api.VerifyCredentials())
and i tried to run:
Traceback (most recent call last):
File "tweepy.py", line 1, in <module>
import twitter
File "/home/rodney/twitter.py", line 1, in <module>
import tweepy
File "/home/rodney/tweepy.py", line 2, in <module>
api = twitter.Api(consumer_key=["X"],
AttributeError: module 'twitter' has no attribute 'Api'
get this error what i do:
if try code:
import twitter
import tweepy
api = twitter.Api(consumer_key=["X"],
consumer_secret=["X"],
access_token_key=["35X-X"],
access_token_secret=["X"])
print(api.VerifyCredentials())
error:
Traceback (most recent call last):
File "tweepy.py", line 1, in <module>
import tweepy
File "/home/rodney/tweepy.py", line 2, in <module>
import twitter
File "/home/rodney/twitter.py", line 10, in <module>
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
AttributeError: module 'tweepy' has no attribute 'OAuthHandler'
Upvotes: 1
Views: 2160
Reputation: 91
If working on pycharm IDE try to add the tweepy library from File-->setting Link:https://www.youtube.com/watch?v=pKzfNBTRx5U
Upvotes: -1
Reputation: 399
Try this
For what you want to do here is the code using tweepy
import tweepy
auth = tweepy.OAuthHandler(consumer_token, consumer_secret)
auth.set_access_token(key, secret)
resp= tweepy.API(auth)
The rest is upon you whatever you want to do. For that you will need cursors, which can be found over here http://docs.tweepy.org/en/v3.5.0/cursor_tutorial.html
Upvotes: 1
Reputation: 5851
pip install python-twitter
Working fine on python3 and python2
Upvotes: -1
Reputation: 10359
Tweepy takes two steps to set up authorisation, as detailed in the documentation:
import tweepy
consumer_key = 'XX'
consumer_secret = 'XXX'
access_token = 'XXXX'
access_token_secret = 'XXXXX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
print api.verify_credentials()
Tweepy is also distinct from python-twitter - you probably don't need both. I'd also avoid calling your file tweepy.py
as this could cause confusion in imports later on.
Upvotes: 1