Shreejay Pendse
Shreejay Pendse

Reputation: 194

tweepy.error.TweepError: [{u'message': u'Text parameter is missing.', u'code': 38}]

I am using tweepy twitter api for python, while using it i got some error, I am not able to use send_direct_message(user/screen_name/user_id, text) this method

Here is my code:-

import tweepy
consumer_key='XXXXXXXXXXXXXXXXX'
consumer_secret='XXXXXXXXXXXXXXXXX'
access_token='XXXXXXXXXXXXXXXXX'
access_token_secret='XXXXXXXXXXXXXXXXX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

API = tweepy.API(auth)

user = API.get_user('SSPendse')
screen_name="CJ0495"
id = 773436067231956992
text="Message Which we have to send must have maximum 140 characters, If it is Greater then the message will be truncated upto 140 characters...."
# re = API.send_direct_message(screen_name, text)
re = API.send_direct_message(id, text)
print re

got following error:-

Traceback (most recent call last):
  File "tweetApi.py", line 36, in <module>
    re = API.send_direct_message(id, text)
  File "/usr/local/lib/python2.7/dist-packages/tweepy/binder.py", line 245, in _call
    return method.execute()
  File "/usr/local/lib/python2.7/dist-packages/tweepy/binder.py", line 229, in execute
    raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: [{u'message': u'Text parameter is missing.', u'code': 38}]

What will be mistake done by me...???

I also have another problem related to tweepy, How can I moved to page two or got more followers in following code

i=1
user = API.get_user('Apple')
followers = API.followers(user.id,-1)
for follower in followers:
    print follower,'\t',i
    i=i+1

if I run the code I got only 5000 followers however if I use user.followers_count it gives 362705 followers (This no. may be changes while You check it) How can I see remaining followers

Thank You... :)

Upvotes: 0

Views: 2585

Answers (1)

Efferalgan
Efferalgan

Reputation: 1701

To solve your first error, replace re = API.send_direct_message(id, text) with re = API.send_direct_message(id, text=text). This function only works if you give it the message as a named parameter. The parameter name you need here is "text", so you might want to change your variable name to avoid confusion. Also, I just tried it, since you are sending a direct message, not a tweet, it will not be truncated to only the first 140 characters.

For your second question, this should do the trick, as explained here:

followers = []
for page in tweepy.Cursor(API.followers, screen_name='Apple').pages():
    followers.extend(page)
    time.sleep(60) #this is here to slow down your requests and prevent you from hitting the rate limit and encountering a new error
print(followers)

Upvotes: 1

Related Questions