What I am trying to do is a twitter bot for retweeting whatever I have in my DMbox.
So I need a few things.
- I need to follow all the users who follow me. (I did that)
- I need to read the DMs( I have to do)
- Tweet the DM (I can do it i guess)
- Delete the Read DMS(I dont think I wil be able to do it without help)
The problem with reading DMs are I am getting all the DMs at once. How can I tweet it one by one, I mean how I can take one DM from this Response I am getting for “$_GET[‘https://api.twitter.com/1/direct_messages.json’%5D”
Now after retweeting all these DMs how can I delete all of them?
If you are using the GET direct_messages method provided by the REST API, you can use a combination of the since_id, max_id, and count to request one DM (count) older than (max_id) or more recent than (since_id) some known DM. https://dev.twitter.com/docs/api/1/get/direct_messages
Here is an example: https://api.twitter.com/1/direct_messages.json?count=1&since_id=1270520569
After you have grabbed the DM and thus, received it’s id, you can grab your next DM using the above code and delete the current message using the POST direct_messages/destroy/:id method also available through the REST API. https://dev.twitter.com/docs/api/1/post/direct_messages/destroy/%3Aid
Here is an example of the delete method: https://api.twitter.com/1/direct_messages/destroy/1270520569.json
To get the first DM that you use to begin your process of retrieving messages, simply use the GET direct_messages with a count of 1 and move either backwards or forwards (max_id or since_id) depending on how Twitter orders the tweets. If they are not ordered by time, you’ll simply have to explore in both directions.