send direct message

1,321 views
Skip to first unread message

Ian macdonald

unread,
Oct 13, 2010, 5:55:37 PM10/13/10
to tweepy
Hi all,

I am new to twitter and python, so probably your worst nightmare :-)

I have followed the tutorial here

http://jmillerinc.com/2010/05/31/twitter-from-the-command-line-in-python-using-oauth/

very clear and precise and got it all working

Then I thought lets try for a direct message as follows

#!/usr/bin/env python

import sys
import tweepy

CONSUMER_KEY = 'my key from twitter'
CONSUMER_SECRET = ' this is the secret'
ACCESS_KEY = 'access key'
ACCESS_SECRET = 'access secret'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
myuser = '201272679'
#api.update_status(sys.argv[1])
api.send_direct_message(myuser, sys.argv[1])

as you can see from the example I have just commented out the
api.update_status and added a call for direct message.

the myuser is the id from the rss at the bottom of my page and I have
also used my page id but get the following error


Traceback (most recent call last):
File "./tweet_me.py", line 15, in <module>
api.send_direct_message(myuser, sys.argv[1])
File "/usr/local/lib/python2.6/dist-packages/tweepy-1.7.1-py2.6.egg/
tweepy/binder.py",
line 179, in _call
return method.execute()
File "/usr/local/lib/python2.6/dist-packages/tweepy-1.7.1-py2.6.egg/
tweepy/binder.py",
line 162, in execute
raise TweepError(error_msg, resp)
tweepy.error.TweepError: Invalid request.


Ubuntu 10.04,

if anyone has time to point out where I am going wrong I would
appreciate it


all the best

Ian

Ian macdonald

unread,
Oct 14, 2010, 10:27:26 AM10/14/10
to tweepy


On Oct 13, 10:55 pm, Ian macdonald <ianma...@gmail.com> wrote:
> Hi all,
>
> I am new to twitter and python, so probably your worst nightmare :-)
>
> I have followed the tutorial here
>
> http://jmillerinc.com/2010/05/31/twitter-from-the-command-line-in-pyt...
I fixed this, just in case anyone else is in my situation

api.send_direct_message(myuser, sys.argv[1])

should be

api.send_direct_message(user_id = myuser, text = sys.argv[1])


cheers

Ian

Josh Roesslein

unread,
Nov 15, 2012, 2:42:57 AM11/15/12
to twe...@googlegroups.com
Twitter requires the users have a mutual friendship (both follow each other) to exchange direct messages.
As for the error message we will print out a more "human" message IF Twitter
provides one in the HTTP response. Otherwise we don't know what went wrong.


On Wed, Nov 14, 2012 at 9:32 PM, Oleg Neumyvakin <advq...@gmail.com> wrote:

There some kind of bug in tweepy. The direct messages can be send if both of twitter accounts are following each other.

And here what's happens if one doesn't follow another one:

>>> api.send_direct_message(screen_name='@Someone', text='test')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/www/apps/envpy27/lib/python2.7/site-packages/tweepy/binder.py", line 185, in _call
    return method.execute()
  File "/var/www/apps/envpy27/lib/python2.7/site-packages/tweepy/binder.py", line 168, in execute
    raise TweepError(error_msg, resp)
tweepy.error.TweepError

As you can see there is no human readable error message.


четверг, 14 октября 2010 г., 4:55:37 UTC+7 пользователь Ian macdonald написал:
Reply all
Reply to author
Forward
0 new messages