Last active
January 17, 2023 18:21
-
-
Save git-jr/b924e1800c11e4b9a9c7767935fdf00d to your computer and use it in GitHub Desktop.
Código para postar um Tweet com um rótulo customizado através da API Tweepy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install tweepy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# importando os módulos | |
import os | |
import tweepy | |
import requests | |
# detalhes pessoais | |
consumer_key = " | |
consumer_secret = " | |
access_token =" | |
access_token_secret = " | |
# autenticação do app | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
# autenticação do usuário | |
auth.set_access_token(access_token, access_token_secret) | |
api = tweepy.API(auth) | |
# Faz um Tweet normal | |
def tweet(texto): | |
api.update_status(status = texto) | |
# Faz um Tweet com imagem | |
def tweet_imagem(url, texto): | |
filename = 'temp.jpg' | |
request = requests.get(url, stream=True) | |
if request.status_code == 200: | |
with open(filename, 'wb') as image: | |
for chunk in request: | |
image.write(chunk) | |
api.update_with_media(filename, status= texto) | |
os.remove(filename) | |
else: | |
print("Não foi possível carregar a imagem") | |
url = "https://media.giphy.com/media/7dzr1iE6DTVSiH2i2a/giphy.gif" | |
texto = "Digite aqui seu texto" | |
tweet_imagem(url, texto) | |
tweet(texto) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mais fácil usar o Twidere, que é tipo uma versão antiga do twitte. so copiar e colar as chaves e depois logar