Featured image of post Cómo tuitear usando la API de Twitter y Google Colaboratory

Cómo tuitear usando la API de Twitter y Google Colaboratory

Lo que necesitas

  • API de Twitter
  • Twitter API SECRET
  • Twitter ACCESS TOKEN
  • Twitter ACCESS TOKEN SECRET
  • Cuenta de Google

Para obtener la API de Twitter, consulta los sitios de referencia.

Procedimiento para tuitear usando la API

  1. Accede a https://colab.research.google.com/
  2. Selecciona “Archivo” → “Nuevo cuaderno”
  3. Pega y ejecuta el siguiente código (usa los valores reales que obtuviste)
1
2
3
4
API_KEY = '9Smu2f2RoLqbVQHQq6n79Z2JW'
API_SECRET = 'uGVRIkLL2l8sRyPv2Lr4mXxXppnQF1isMoRnvktcXCtFgAK2R8'
ACCESS_TOKEN = '0367292979164670705-7hSErDoQbO6fkFtnn5UY0vqpvecy0O'
ACCESS_TOKEN_SECRET = 'pUv81U9GVzZirz5g4AxZPHAJ4GpSXnBo8GUcZ1egtjw9q'
  1. Pega y ejecuta el siguiente código
1
import tweepy
  1. Pega y ejecuta el siguiente código (API v1.1)
1
2
3
4
auth = tweepy.OAuthHandler(API_KEY, API_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
api.update_status("hello")

→ Se publicará el tuit hello

  1. Pega y ejecuta el siguiente código (API v2.0)
1
2
client = tweepy.Client(consumer_key=API_KEY, consumer_secret=API_SECRET, access_token=ACCESS_TOKEN, access_token_secret=ACCESS_TOKEN_SECRET)
client.create_tweet(text='hello v2')

→ Se publicará el tuit hello v2

Eso es todo.

Referencias

comments powered by Disqus