0

what I want is to eliminate the last tweet, for that I use the following:

    l = len(sys.argv)

if l >= 2:
    twid = sys.argv[1]
else:
    twid = input("ID number of tweet to delete: ")

try:
    tweet = twitter.destroy_status(id=twid)
except TwythonError as e:
    print(e)

It runs perfect.

You see I need the "ID" but not how to get it.

I hope you can help me, thanks!

krowa
  • 1
  • 2
  • 1
    um. As in the twitter ID or the ID in your program? I assume the id is in the URL when you click a tweet - https://twitter.com/cgpgrey/status/752232623968137216 i.e. 752232623968137216 in this case. – Tim Jul 11 '16 at 17:21
  • @Tim Yes, this ID. I need to somehow get it and store it in a variable – krowa Jul 11 '16 at 17:32
  • Well, select it. Copy it. Paste it. Enter it as input, then it's stored in `twid`. – Tim Jul 11 '16 at 17:35
  • But I need it automatic! I have to run a script (made in python) to delete the last tweet. – krowa Jul 11 '16 at 17:37
  • Well how does twython get tweets? Try `twitter.get_home_timeline()`. – Tim Jul 11 '16 at 17:37

2 Answers2

0

I think this can help you.

user_timeline=twitter.get_user_timeline(screen_name="BarackObama", count=20)
for tweet in user_timeline:
    print tweet["id"]

It prints the 20 lastest tweets id of Barack Obama.

Let me know if that is what you are looking for.

Naster
  • 704
  • 1
  • 5
  • 18
0

You can use get_user_timeline with your personal screen name to retrieve the tweet, and then access it with tweet[0] since it will be in the first index.

tweet = twitter.get_user_timeline(
            screen_name=YOUR_SCREEN_NAME,
            count=1)
twitter.destroy_status(id=tweet[0]['id'])