What should be the callback when using GitHub Actions? #2142
-
QuestionMy application runs through a GitHub Action.What should my callback be? Então, atualizei aquele antigo modelo: # OLD - It worked in v1
auth = OAuthHandler(getenv('API_KEY'),
getenv('API_KEY_SECRET'))
auth.set_access_token(getenv('ACCESS_TOKEN'),
getenv('ACCESS_TOKEN_SECRET'))
api = API(auth)
api.verify_credentials() But I can't get this to work. Relevant Codedef twitter_connect(tweet_list):
auth = OAuth2UserHandler(client_id=getenv('CLIENT_ID'),
redirect_uri='https://github.com/arnonrdp/Bot-Deschamps-Newsletter',
scope=['tweet.write'],
client_secret=getenv('API_KEY_SECRET'))
url = auth.get_authorization_url()
access_token = auth.fetch_token(url)
api = Client(access_token)
try:
api.verify_credentials()
print('Good news, you are logged!')
prepare_tweet(tweet_list, api)
except Exception as e:
print('Bad news, will try again in 2 minutes.\n', e)
sleep(120)
twitter_connect(tweet_list) TracebackTraceback (most recent call last):
File "/Users/arnon/Public/GitHub/Bot-Deschamps-Newsletter/post_tweet.py", line 15, in twitter_connect
access_token = auth.fetch_token(url)
File "/Users/arnon/Public/GitHub/Bot-Deschamps-Newsletter/.venv/lib/python3.9/site-packages/tweepy/auth.py", line 217, in fetch_token
return super().fetch_token(
File "/Users/arnon/Public/GitHub/Bot-Deschamps-Newsletter/.venv/lib/python3.9/site-packages/requests_oauthlib/oauth2_session.py", line 244, in fetch_token
self._client.parse_request_uri_response(
File "/Users/arnon/Public/GitHub/Bot-Deschamps-Newsletter/.venv/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/clients/web_application.py", line 220, in parse_request_uri_response
response = parse_authorization_code_response(uri, state=state)
File "/Users/arnon/Public/GitHub/Bot-Deschamps-Newsletter/.venv/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 284, in parse_authorization_code_response
raise MissingCodeError("Missing code parameter in response.")
oauthlib.oauth2.rfc6749.errors.MissingCodeError: (missing_code) Missing code parameter in response.
Auth:
https://twitter.com/i/oauth2/authorize?response_type=code&client_id=dUNFZEN5dVZVZGItcmZKWWFYQXQ6MTpjaQ&redirect_uri=https%3A%2F%2Fgithub.com%2Farnonrdp%2FBot-Deschamps-Newsletter&scope=tweet.write&state=cvGy54WBy4pYUrrjQW7jzPxIFFJVCL&code_challenge=CTcbeAR3NkSBBiLLGZ-l1lqsjRnZW35Wy0qm7_oO2pg&code_challenge_method=S256 Twitter API Access PlanFree Tweepy Version4.14.0 Checklist
Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 16 replies
-
You need to actually use the authorization URL, instead of just passing it to You can continue using OAuth 1.0a User Context with Twitter API v2 though. Also note, |
Beta Was this translation helpful? Give feedback.
-
Try this: from tweepy import Client
def twitter_connect(tweet_list):
client = Client(
consumer_key=getenv('API_KEY'),
consumer_secret=getenv('API_KEY_SECRET'),
access_token=getenv('ACCESS_TOKEN'),
access_token_secret=getenv('ACCESS_TOKEN_SECRET')
)
prepare_tweet(tweet_list, client) |
Beta Was this translation helpful? Give feedback.
Try this: