I'm trying to use the python-twitter module, but still having problems initiating the twitter.Api(). I've checked and rechecked that no other file named twitter.py or twitter.pyc is on my system. On a clean install i first try to
>>> import twitter
and correctly get a response of 'module unknown'
I do a easy_install twitter, successfull.
Then do
>>> import twitter
>>> testapi = twitter.Api()
The response is
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
testapi = twitter.Api()
AttributeError: 'module' object has no attribute 'Api'
>>>
I'm exhausted trying to locate the problem here, please help.
It appears that you are trying to follow the documentation for one Python Twitter module when you are in fact using another Python Twitter module.
The Api() method call you mention is part of this Python Twitter module. However, when you use easy_install twitter, you actually get this other Python Twitter module.
Related
I am trying to run the code from https://github.com/CreepyD246/Twitter-Reply-Bot/blob/main/TwitterReplyBot.py on Replit.
#Importing modules/libraries
import tweepy
import time
import os
# Initialization code
auth = tweepy.OAuthHandler(os.getenv("key2"),os.getenv("skey2"))
auth.set_access_token(os.getenv("token2"),os.getenv("stoken2"))
api = tweepy.API(auth)
# Some important variables which will be used later
bot_id = int(api.me().id_str)
#Other things after
But I get this error:
Traceback (most recent call last):
File "main.py", line 12, in <module>
bot_id = int(api.me().id_str)
AttributeError: 'API' object has no attribute 'me'
I don't find anything in the Tweepy's documentation about API.me() so what's wrong?
The Tweepy version is 4.1.0.
Tweepy v4.0.0 removed API.me.
You can use API.verify_credentials instead.
Tweepy v4.0.0 removed API.me use API.get_user
That is the replacement for now
yes api.get_user is the replacement in tweepy v4.0.0
This worked for me api.get_user(screen_name="replaceWithYourTwitterUsername")
I am trying to use the python twitter API but it can't find the Twitter class.
https://pypi.python.org/pypi/twitter
For instance I do the following without any errors:
from twitter import *
But when I do:
>>> t = Twitter(auth)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Twitter' is not defined
What am I missing? Is there a different python twitter library I need to install?
Try using the tweepy library, easy to use. Take a look at http://www.tweepy.org/
Here is a code example:
import tweepy
auth = tweepy.OAuthHandler('','')
auth.set_access_token('', '')
api = tweepy.API(auth)
public_tweets = api.followers_ids()
for tweet in public_tweets:
print len(public_tweets)
I am trying to use the Google Drive API to download publicly available files however whenever I try to proceed I get an import error.
For reference, I have successfully set up the OAuth2 such that I have a client id as well as a client secret , and a redirect url however when I try setting it up I get an error saying the object has no attribute urllen
>>> from apiclient.discovery import build
>>> from oauth2client.client import OAuth2WebServerFlow
>>> flow = OAuth2WebServerFlow(client_id='not_showing_client_id', client_secret='not_showing_secret_id', scope='https://www.googleapis.com/auth/drive', redirect_uri='https://www.example.com/oauth2callback')
>>> auth_uri = flow.step1_get_authorize_url()
>>> code = '4/E4h7XYQXXbVNMfOqA5QzF-7gGMagHSWm__KIH6GSSU4#'
>>> credentials = flow.step2_exchange(code)
And then I get the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/oauth2client/util.py", line
137, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Library/Python/2.7/site-packages/oauth2client/client.py", line
1980, in step2_exchange
body = urllib.parse.urlencode(post_data)
AttributeError: 'Module_six_moves_urllib_parse' object has no attribute
'urlencode'
Any help would be appreciated, also would someone mind enlightening me as to how I instantiate a drive_file because according to https://developers.google.com/drive/web/manage-downloads, I need to instantiate one and I am unsure of how to do so.
Edit: So I figured out why I was getting the error I got before. If anyone else is having the same problem then try running.
sudo pip install -I google-api-python-client==1.3.2
However I am still unclear about the drive instance so any help with that would be appreciated.
Edit 2: Okay so I figured out the answer to my whole question. The drive instance is just the metadata which results when we use the API to search for a file based on its id
So as I said in my edits try the sudo pip install and a file instance is just a dictionary of meta data.
I installed everything as it says on the FlickrAPI homepage but when I try to run:
import flickrapi
api_key = '1a4c975fa83048436a2086bcab7d2290'
api_password = '5e069eae20e60297'
flickrclient = flickrapi.FlickAPI(api_key, api_password)
favourites = flickrClient.favorites_getPublicList(user_id='userid')
photos = flickr.photos_search(user_id='73509078#N00', per_page='10')
sets = flickr.photosets_getList(user_id='73509078#N00')
for photo in favourites.photos[0].photo:
print photo['title']
I get this message from the command prompt:
C:\Users\Desktop>python api.py
Traceback (most recent call last):
File "api.py", line 4, in <module>
flickrclient = flickrapi.FlickAPI(api_key, api_password)
AttributeError: 'module' object has no attribute 'FlickAPI'
Any ideas?? I have tried almost everything
FlickAPI is not the same as FlickrAPI. You're missing an r.
The file C:\Users\XXXXXX\Desktop\FLICKR API\flickrapi.py is not part of the flickrapi package. Please rename it, it is masking the real library. Right now it is being imported instead of the installed package.
The flickrapi package itself consists of a directory with a __init__.py file inside of it. Printing flickrapi.__file__ should result in a path ending in flickrapi\__init__.py.
In your "flickrclient = flickrapi.FlickAPI" line, you're missing an 'r' in FlickAPI.
Also, on the next line, your *"user_id='userid'"* argument needs an actual user ID, such as '999999#N99'
Hopefully you found that & got this working a few months ago! :)
I am trying to develop a gtk3 desktop application using python to perform the basic twitter functions like accessing the home timeline of a user, making tweets etc.
I am using python-twitter library, but am unable to find the API call for the purpose. I checked and saw there were a few patches , but they dont seem to work. the rest of the functions I am able to accomplish using the library.
I need help!!!
[edit]
this is the error i am facing when i tried using a fork of the python-twitter library, as given on: http://github.com/jaytaylor/python-twitter-api
Error:
>>api.getUserTimeline('gaurav_sood91')
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "twitter.py", line 2646, in getUserTimeline
self._checkForTwitterError(data)
File "twitter.py", line 3861, in _checkForTwitterError
if data.has_key('next_cursor'):
AttributeError: 'list' object has no attribute 'has_key'
Using the python-twitter module from code.google.com, documentation here.
Accessing user timelines:
import twitter
api = twitter.Api()
statuses = api.GetUserTimeline('#gaurav_sood91')
print [s.text for s in statuses]
Posting tweets:
import twitter
api = twitter.Api(consumer_key='consumer_key',
consumer_secret='consumer_secret',
access_token_key='access_token',
access_token_secret='access_token_secret')
status = api.PostUpdate('This is my update text.')
Edit for applying GetHomeTimeline patch:
Disclaimer: I'm on Windows, so you may need to change these steps a bit.
Download python-twitter
Extract to folder
Download 0002-Support-for-home-timeline.patch file from issue 152
Copy/move patch file to root of extracted python-twitter directory (there should be a file named twitter.py in this dir)
Run command: patch twitter.py 0002-Support-for-home-timeline.patch, you should get a message that patch succeeded
In same directory, run command: python setup.py install
Run interactive python shell: import twitter, dir(twitter.Api)
You should see the GetHomeTimeline method listed.
Update for GetHomeTimeline:
Found patch in issue 152 that works well using OAuth and JSON parse method that is now part of Status class. Sample code:
import twitter
api = twitter.Api(consumer_key='consumer_key',
consumer_secret='consumer_secret',
access_token_key='access_token',
access_token_secret='access_token_secret')
statuses = api.GetHomeTimeline()
print [s.text for s in statuses]