-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Direct Message API changes #1081
Comments
twitter is going to shut down Direct Message API today. Is there any update? Thanks. |
Update from Twiiter:
|
Because I just need to send direct message, where is a quick fix for anyone who wants it right now: If you are on version 2.3.0 (like me), that is all you need. But if you are on version 3.6.0, then you need add 3 lines of code to binder.py (quick and dirty fix) You can send DM like:
|
@do-n-khanh When I'm using your api.py over a 3.6.0 it doesn't work
try :
self.config = ConfigParser.ConfigParser()
self.config.read(os.path.expanduser('~/Prog/config/.twitterrc'))
consumer_key=self.config.get("security","consumer_key")
access_token=self.config.get("security", "access_token")
consumer_secret=self.config.get("security","consumer_secret")
access_token_secret=self.config.get("security","access_token_secret")
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
except ConfigParser.NoSectionError:
print("Section security non trouvée")
self.configT = ConfigParser.ConfigParser()
self.configT.read(os.path.expanduser('~/Prog/config/.TwittingDoor'))
try :
self.destname=self.configT.get("twitter","destname")
except ConfigParser.NoSectionError:
print("Section twitter non trouvée")
self.api = tweepy.API(auth)
self.send_direct_message(self.destname,"test")
def send_direct_message(self,dest, msg):
event = {
"event": {
"type": "message_create",
"message_create": {
"target": {
"recipient_id": dest
},
"message_data": {
"text": msg
}
}
}
}
self.api.send_direct_message_new(event) |
@StefTocup: Sorry, my version is 2.3.0. Let's me see how it works in 3.6.0 |
@StefTocup: I made a dirty fix to make it work in 3.6.0 by adding 3 lines of code to binder.py Let's me know if it works for you. |
@do-n-khanh it's working with this quick fix.
|
yes, it is because twitter api only allow user id. |
It is not working. |
Hi, has anyone picked this up? Do we have an idea of when Tweepy will be migrated to the new API? |
Please paste the error log. |
I'm using tweepy 3.6.0 and it doesn't work for me either. I added the lines from your commit do-n-khanh@c978749 and noticed that the path seems to be Printing
What I don't understand is how this should fix the problem. You're essentially removing the two important arguments to send a DM. But then again I didn't look into tweepy's code so I have 0 understanding of what tweepy does. I just seems quite weird and looks like you're not just preventing the error message but also the DM from being sent. Figured out that the path seems to have been changed to this. (https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-event) Now I just need to figure out how to modify the data tweepy sends so that the Twitter API properly understands my request. |
Hi Exceen, it works for me (on 2.3.0 and 3.6.0) and @StefTocup (3.6.0) if you are on version 3.6.0, then you need:
To send DM, you need to use
Note that we are using send_direct_message_new. |
I fixed "get" part of DM. Waiting my pull request to be merged You can find pull request at: #1109 |
Hi do-n-khanh I´m on version 3.6.0. I added the 2 methods and the lines on binder.py but when I import tweepy this new funtion "send_direct_message_new" is not available. I get the error api object has no attribute "send_direct_message_new" I started to use tweepy and python a couple o months ago. Maybe i do something wrong. Thanks in advance for your help |
what framework or environment are you working on? you need to make sure that the modified tweepy lib is called instead of the old one. and please make sure 2 methods are put in api.py file. lastly, you need to paste the error log so that i can figure out the error. |
do-n-khanh, your point. I had changed a old lib.... now it works fine!!! thanks a lot!!! |
Hi do-nkhanh, Have you met this error: "tweepy.error.TweepError: [{u'message': u'You cannot send messages to users who are not following you.', u'code': 150}]" I wanted to use send_direct_message_new to send message to some users who is not following me and whom I'm not following too. Any ideas? Thanks! |
that is impossible due to twitter rules |
I had to apply the above fixes ( #1081 (comment) ) to get version 3.7.0 to work. That was the version |
Do I need to fetch it manually from bind_api? https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference |
I'm working on a fork of tweepy to update the direct message endpoints as well as adding the new functionality of quick replies, buttons and the async media upload that is now required for direct messages. I'm also working on including the new Welcome Message endpoints and Welcome Message Rules. There's been a fair bit of work involved in this and it's a pretty significant update as it affects multiple files in tweepy (api, binder, cursor, models, parsers), adds a new file (mediaasync.py) that is a modified version of binder.py for the async media uploader. These updates also add to some of the key design methodology on which tweepy operates in api.py and binder.py. The cursor styles for direct messages and welcome messages are also different to the standard cursor method used by the API which adds further complexity to the updates. You can find the fork I'm working on here https://github.com/machine-uprising/tweepy/tree/direct_messages To keep track of the changes made for documentation and for testing I have a wiki setup in this repository - https://github.com/machine-uprising/tweepy-devtest/wiki The wiki has details about the updates being made and examples for testing/using the new endpoints. This would be a pretty major pull request. Also, because of the changes required the Travis CI tests are failing on the new endpoints of direct messages and will likely require rerecording the cassettes. This would need input from @Harmon758 and/or @joshthecoder If anyone wants to setup their own virtual environment and run some testing that would be a great help. |
Hi, I'm using 3.7.0 and DM methods are still not working. There are any ways to get it fixed? |
I've now made a branch (https://github.com/tweepy/tweepy/tree/dm-migration) and draft PR (#1228) for the Direct Message migration. It should fully support the new changes. @huangweibuct This is not something that Twitter allows and is consistent with the website/app. @machine-uprising #1228 simply restores basic DM functionality. |
Twitter is deprecating some of it's REST API endpoints for Direct Messages on August 16, 2018 and replacing them with new endpoints that require changes in how data is sent, they will also return DMs with a different format. More details in the Direct Message Migration guide and in the announcement.
Edit: new reminder from twitter: https://twittercommunity.com/t/reminder-site-streams-user-streams-and-legacy-dm-endpoints-will-be-sunset-august-16th/109482
The text was updated successfully, but these errors were encountered: