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) |
Pela descrição do erro algumas permissões não foram ativadas, da uma olhada no tutorial atualizado: https://youtu.be/QFGIinFGFfU
mais fácil usar o Twidere, que é tipo uma versão antiga do twitte. so copiar e colar as chaves e depois logar
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Help, o meu ta dando esse erro aqui, sou meio leigo nesse assunto então não sei o que fazer.
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in
start(fakepyfile,mainpyfile)
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), main.dict)
File "", line 18, in
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.9/site-packages/tweepy/api.py", line 46, in wrapper
return method(*args, **kwargs)
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.9/site-packages/tweepy/api.py", line 1121, in update_status
return self.request(
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.9/site-packages/tweepy/api.py", line 259, in request
raise Forbidden(resp)
tweepy.errors.Forbidden: 403 Forbidden
453 - You currently have Essential access which includes access to Twitter API v2 endpoints only. If you need access to this endpoint, you’ll need to apply for Elevated access via the Developer Portal. You can learn more here: https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve
[Program finished]