<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Twitter API on kenji.blog</title><link>http://kenji.blog/pt/tags/twitter-api/</link><description>Recent content in Twitter API on kenji.blog</description><generator>Hugo -- gohugo.io</generator><language>pt</language><copyright>kenjinote</copyright><lastBuildDate>Sat, 08 Apr 2023 18:48:32 +0900</lastBuildDate><atom:link href="http://kenji.blog/pt/tags/twitter-api/index.xml" rel="self" type="application/rss+xml"/><item><title>Como twittar usando a API do Twitter e o Google Colaboratory</title><link>http://kenji.blog/pt/p/como-twittar-usando-a-api-do-twitter-e-o-google-colaboratory/</link><pubDate>Sat, 08 Apr 2023 18:48:32 +0900</pubDate><guid>http://kenji.blog/pt/p/como-twittar-usando-a-api-do-twitter-e-o-google-colaboratory/</guid><description>&lt;img src="http://kenji.blog/p/twitter-api%E3%81%A8google-colaboratory%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6tweet%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95/img.png" alt="Featured image of post Como twittar usando a API do Twitter e o Google Colaboratory" />&lt;h1 id="o-que-você-precisa">O que você precisa
&lt;/h1>&lt;ul>
&lt;li>Twitter API&lt;/li>
&lt;li>Twitter API SECRET&lt;/li>
&lt;li>Twitter ACCESS TOKEN&lt;/li>
&lt;li>Twitter ACCESS TOKEN SECRET&lt;/li>
&lt;li>Conta do Google&lt;/li>
&lt;/ul>
&lt;p>Consulte o site de referência para saber como obter a API do Twitter.&lt;/p>
&lt;h1 id="passos-para-twittar-usando-a-api">Passos para twittar usando a API
&lt;/h1>&lt;ol>
&lt;li>Acesse &lt;a class="link" href="https://colab.research.google.com/" target="_blank" rel="noopener"
>https://colab.research.google.com/&lt;/a>&lt;/li>
&lt;li>Selecione &amp;ldquo;Arquivo&amp;rdquo; -&amp;gt; &amp;ldquo;Novo notebook&amp;rdquo;&lt;/li>
&lt;li>Cole e execute o código abaixo (use seus próprios valores reais obtidos)&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">API_KEY = &amp;#39;9Smu2f2RoLqbVQHQq6n79Z2JW&amp;#39;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">API_SECRET = &amp;#39;uGVRIkLL2l8sRyPv2Lr4mXxXppnQF1isMoRnvktcXCtFgAK2R8&amp;#39;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">ACCESS_TOKEN = &amp;#39;0367292979164670705-7hSErDoQbO6fkFtnn5UY0vqpvecy0O&amp;#39;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">ACCESS_TOKEN_SECRET = &amp;#39;pUv81U9GVzZirz5g4AxZPHAJ4GpSXnBo8GUcZ1egtjw9q&amp;#39;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;ol start="3">
&lt;li>Cole e execute o código abaixo&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">import tweepy
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;ol start="4">
&lt;li>Cole e execute o código abaixo (API v1.1)&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">auth = tweepy.OAuthHandler(API_KEY, API_SECRET)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">api = tweepy.API(auth)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">api.update_status(&amp;#34;hello&amp;#34;)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>→ Um tweet dizendo &lt;code>hello&lt;/code> será postado.&lt;/p>
&lt;ol start="5">
&lt;li>Cole e execute o código abaixo (API v2.0)&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">client = tweepy.Client(consumer_key=API_KEY, consumer_secret=API_SECRET, access_token=ACCESS_TOKEN, access_token_secret=ACCESS_TOKEN_SECRET)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">client.create_tweet(text=&amp;#39;hello v2&amp;#39;)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>→ Um tweet dizendo &lt;code>hello v2&lt;/code> será postado.&lt;/p>
&lt;p>É isso.&lt;/p>
&lt;h1 id="referência">Referência
&lt;/h1>&lt;ul>
&lt;li>&lt;a class="link" href="https://bloomtectec.com/twitter-api-application-procedure/" target="_blank" rel="noopener"
>【A partir de abril de 2021】Explicação detalhada da solicitação de uso da API do Twitter com frases de exemplo de uso e capturas de tela&lt;/a>&lt;/li>
&lt;li>&lt;a class="link" href="https://bloomtectec.com/use-twitter-api-in-google-colab/" target="_blank" rel="noopener"
>【Sem necessidade de configurações complicadas!】O Google Colaboratory é recomendado como um ambiente de teste para a API do Twitter 【Código-fonte também compartilhado】&lt;/a>&lt;/li>
&lt;li>&lt;a class="link" href="https://3pysci.com/tweepy-28/" target="_blank" rel="noopener"
>【Tweepy】Twitter API v2: Tweets, respostas, tweets com enquetes, tweets com mídia (v1.1) [Python]&lt;/a>&lt;/li>
&lt;/ul></description></item></channel></rss>