# Twitter-API mit Twython oder Tweepy nutzen --- ### [pip3](https://packaging.python.org/guides/installing-using-linux-tools/#installing-pip-setuptools-wheel-with-linux-package-managers) und [twython](https://twython.readthedocs.io/en/latest/index.html) installieren ```python= sudo apt-get install -y python3-pip sudo pip3 install twython ``` ### [Twitter Developer-Account](https://developer.twitter.com/) einrichten und [Twitter-App](https://developer.twitter.com/en/apps) erstellen für die API-Keys und Access-Tokens Deutschsprachige Anleitung: https://www.it-talents.de/blog/gastbeitraege/eigener-twitter-bot ### Hallo Tweet erstellen ``` sudo nano tweet.py ``` mit folgendem Inhalt: ```python= from twython import Twython tweet = "Twython läuft! Yippieh! " #Hier musst du deine Daten einfügen! apiKey = 'XXX' apiSecret = 'XXX' accessToken = 'XXX' accessTokenSecret = 'XXX' api = Twython(apiKey,apiSecret,accessToken,accessTokenSecret) api.update_status(status=tweet) ```` ausführen mit: ``` python3 tweet.py ``` ### Ergebnis  Tweet-URL: [https://twitter.com/feedbotrss/status/1168893306983591936](https://twitter.com/feedbotrss/status/1168893306983591936) Nächster Schritt: Twitterbot entwickeln ## mit Tweepy https://realpython.com/twitter-bot-python-tweepy/ Tweepy installieren ```python= pip3 install tweepy ``` Tweet erstellen ``` sudo nano twee.py ``` ```python= import tweepy # Authentifizierung auf Twitter auth = tweepy.OAuthHandler("CONSUMER_KEY", "CONSUMER_SECRET") auth.set_access_token("ACCESS_TOKEN", "ACCESS_TOKEN_SECRET") # Erstelle ein API Objekt api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) # Erstelle einen Tweet api.update_status("Twitterbot geht auch mit Tweepy") ``` Twittern ``` python3 twee.py ``` ### Ergebnis  Tweet-URL: [https://twitter.com/feedbotrss/status/1181202221373022209](https://twitter.com/feedbotrss/status/1181202221373022209) Weiterführend zu Tweepy: https://realpython.com/twitter-bot-python-tweepy/#creating-twitter-api-authentication-credentials http://docs.tweepy.org/en/latest/auth_tutorial.html#auth-tutorial # RSS-Bot oder Hashtag retweeten https://github.com/peterdalle/twitterbot Installieren: ``` pip3 install feedparser ```` Code: https://github.com/peterdalle/twitterbot/blob/master/twitterbot.py kopieren in neu angelegte Python-Datei: ```sudo nano twitterbot.py``` Cron Job anlegen ``` crontab -e ``` ``` # Alle 15 Minuten Keywords/Hashtags retweeten: */15 * * * * python3 twitterbot.py rt ``` https://www.freecodecamp.org/news/creating-a-twitter-bot-in-python-with-tweepy-ac524157a607/ Weiterführend: * https://www.earthdatascience.org/courses/earth-analytics-python/using-apis-natural-language-processing-twitter/analyze-tweet-sentiments-in-python/ * https://medium.com/@shihao1007/https-medium-com-shihao1007-live-twitter-data-analysis-and-visualization-using-tweepy-and-plotly-dash-9618d9b092a4 * ## Twitter Data-Science How To Use Twitter Search – Advanced Guide by @Luca https://freshvanroot.com/blog/2019/twitter-search-guide-by-luca/ https://docs.google.com/presentation/d/e/2PACX-1vSsYN0ViHXP1faK1YkTveLYs0fCRfIe_362VON3yW9f8o_f0mrgb3SqfnhCiQa_Vq2KtyFiGanbPWSp/pub?start=false&loop=false&slide=id.g35f391192_00 How to collect any Twitter follower network with the Python script twecoll https://lucahammer.com/2016/09/07/how-to-collect-any-twitter-follower-network-with-the-python-script-twecoll/ https://accountanalysis.app/ * twecoll3 https://github.com/lucahammer/twecoll3 * https://www.br.de/nachrichten/netzwelt/so-haben-wir-die-landtagswahl-in-bayern-auf-twitter-analysiert,R7JMKZP * ## Anaconda - searchtweets - Twitter Premium API https://medium.com/@Luca/collecting-old-tweets-with-the-twitter-premium-api-and-python-e52773d094bd
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up