twitter全自动发推
by Monica Powell
莫妮卡·鲍威尔(Monica Powell)
我如何在5分钟内自动创建FreeCodeCampers的Twitter列表 (How I automatically created a Twitter List of FreeCodeCampers in 5 minutes)
使用Twython Twitter API包装器将用户添加到Twitter列表 (Using Twython Twitter API wrapper to add users to a Twitter List)
We are going to create a Python script that will automatically search Twitter for individuals who use the #freeCodeCamp hashtag and add them to a Twitter list of “FreeCodeCampers”. Twitter lists are a way to curate a group of individuals on Twitter and collect all of their tweets in a stream, without having to follow each individual accounts. Twitter lists can contain up to 5,000 individual Twitter accounts.
我们将创建一个Python脚本,该脚本将自动在Twitter上搜索使用#freeCodeCamp标签的个人,并将其添加到“ FreeCodeCampers”的Twitter列表中。 Twitter列表是一种在Twitter上策划一组个人并在流中收集其所有tweet的方式,而不必关注每个个人帐户。 Twitter列表最多可以包含5,000个单独的Twitter帐户。
We can accomplish this by doing the following:
我们可以通过执行以下操作来完成此任务:
- Installing the necessary Python packages 安装必要的Python软件包
- Registering an application with Twitter 在Twitter上注册应用程序
- Generating and accessing our Twitter credentials 生成和访问我们的Twitter凭证
So lets get started.
因此,让我们开始吧。
1.安装必要的Python软件包 (1. Installing the necessary Python packages)
Create a file named addToFreeCodeCampList.py
, that will contain our main script and then import two Python modules into this file:
创建一个名为addToFreeCodeCampList.py
的文件,该文件将包含我们的主脚本,然后将两个Python模块导入该文件:
Import Config: In the same directory as our
addToFreeCodeCampList.py
script, create a file namedconfig.py
that stores our confidential Twitter API credentials. We are going to import our API credentials from that file into ouraddToFreeCodeCampList.py
script by including the lineimport config
. Twitter requires a valid API key, API secret, access token and token secret for all API requests.导入配置: