Skip to content

Instantly share code, notes, and snippets.

@edsu
Last active April 29, 2021 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edsu/b0efc3b4b4281aee794a4a6869065584 to your computer and use it in GitHub Desktop.
Save edsu/b0efc3b4b4281aee794a4a6869065584 to your computer and use it in GitHub Desktop.
This script surfs errors from the sample stream Twitter API. These come from trying to get user and tweet expansions for users and tweets that have been suspended, deleted or protected.
#!/usr/bin/env python3
# This script surfs errors from the sample stream Twitter API
# these come from trying to get user and tweet expansions for users and tweets
# that have been suspended, deleted or protected
import os
import twarc
import dotenv
dotenv.load_dotenv()
bearer_token = os.environ.get('BEARER_TOKEN')
twitter = twarc.client2.Twarc2(bearer_token=bearer_token)
for resp in twitter.sample():
for error in resp.get('errors', []):
print(error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment