当我尝试使用tweepy进行twitter身份验证时,我收到以下错误.
File "/usr/local/lib/python2.7/dist-packages/tweepy/models.py", line 146, in followers
return self._api.followers(user_id=self.id, **kargs)
File "/usr/local/lib/python2.7/dist-packages/tweepy/binder.py", line 197, in _call
return method.execute()
File "/usr/local/lib/python2.7/dist-packages/tweepy/binder.py", line 173, in execute
raise TweepError(error_msg, resp)
tweepy.error.TweepError: Not authorized.
Run Code Online (Sandbox Code Playgroud)
我不是在构建一个Web应用程序.因此,身份验证更简单.
consumer_key="----------"
consumer_secret="----------"
access_token="--------------"
access_token_secret="-----------------"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
api.get_user('---').followers()
Run Code Online (Sandbox Code Playgroud) 在Python 3中,我制作程序以在Twitter中提取帖子和喜欢:
import tweepy
import pandas as pd
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
Run Code Online (Sandbox Code Playgroud)
此函数接收配置文件的教学分类(仅适用于数据库组织)和配置文件的名称.它创建一个包含字典的列表,然后返回:
def linhadotempo(posicao, valor):
tela = api.user_timeline(valor)
bolha = []
for status in tela:
dicionario = {"nome": valor, "posicionamento": posicao, "posts_links": status.text, "curtidas": status.favorite_count}
bolha.append(dicionario)
return bolha
Run Code Online (Sandbox Code Playgroud)
Twitter个人资料的名称列表及其教学评级.然后转换成数据帧:
data = {
'nome': ['jeanwyllys_real', 'lucianagenro', 'jairbolsonaro', 'MBLivre'],
'posicionamento': ['esquerda', 'esquerda', 'direita', 'direita']
}
perfis = pd.DataFrame(data, columns=['nome','posicionamento'])
perfis.reset_index()
index nome posicionamento
0 …Run Code Online (Sandbox Code Playgroud)