Skip to content

Instantly share code, notes, and snippets.

@git-jr
Last active January 17, 2023 18:21
Show Gist options
  • Save git-jr/b924e1800c11e4b9a9c7767935fdf00d to your computer and use it in GitHub Desktop.
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
# 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)
@git-jr
Copy link
Author

git-jr commented Jun 18, 2020

Como você planeja usar isso?

  • (How will you use the Twitter API for Data?)

I intend to use the API to create non-profit applications and just for fun. Specifically for creating a client application to make tweets with a different label than "Twitter for Iphone" or "Twitter For Android".

Como esse app vai usar a API para Tweetar ou similares?

  • (Please describe you planned use of these features: Tweet, Retweet, Like, Follow, or Direct Message functionally)

I want to create a n application that will allow the connected user to Tweet through a command terminal using the Python programming language.

Descreva seu novo projeto

  • Describe your new Project

Project test for learn how the api work

Descrição do app

  • Description

Esse aplicativo será utilizado para realizar tweets com um rótulo customizado, exemplo: "Twittado de uma geladeira Samsung"

@Junim397
Copy link

Existe algum código que eu consiga postar com foto? eu achei sites em inglês mas com nenhum código eu consegui fazer isso, tem alguma outra versão desse que tá aí?

@amariaclarinha
Copy link

Twitter for Iphone

@amariaclarinha
Copy link

Twitter for Iphone

@luvschangki
Copy link

twitter for ateez's dorm

@git-jr
Copy link
Author

git-jr commented May 17, 2021

Existe algum código que eu consiga postar com foto? eu achei sites em inglês mas com nenhum código eu consegui fazer isso, tem alguma outra versão desse que tá aí?

Sim, existe um código e acabei de adicioná-lo

@lucas-rribeiro
Copy link

image
image

Estou conseguindo acessar os tweets da timeline mas não consigo postar nenhum, sempre tomo um 401 Unauthorized.

@git-jr
Copy link
Author

git-jr commented Oct 9, 2021

Você ativou as permissões de escrita como mostrei aqui?: https://youtu.be/QFGIinFGFfU?t=508

@lucas-rribeiro
Copy link

Sim, descobri vendo um outro vídeo que a a permissão estava só para leitura

@021Belo
Copy link

021Belo commented Feb 11, 2022

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]

@git-jr
Copy link
Author

git-jr commented Feb 11, 2022

Pela descrição do erro algumas permissões não foram ativadas, da uma olhada no tutorial atualizado: https://youtu.be/QFGIinFGFfU

@Gardemi14
Copy link

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