[GH-ISSUE #74] authenticating requests to the Twitter API v2 endpoints #10

Closed
opened 2026-09-02 13:08:56 +02:00 by TheLovinator · 2 comments
Owner

Originally created by @jedimage on GitHub (Mar 23, 2023).
Original GitHub issue: https://github.com/TheLovinator1/discord-twitter-webhooks/issues/74

I've config my .env

WEBHOOK_URL=https://discord.com/api/webhooks/foo/bar
BEARER_TOKEN=AAAAAAAAAAAAAAAAAAAAA
RULE="(from:mytest_account)"

ERROR_WEBHOOK=https://discord.com/api/webhooks/foo/bar
SEND_ERRORS=True
LOG_LEVEL=DEBUG

and config docker-compose to

version: "3"

services:
  discord-twitter-webhooks:
    image: thelovinator/discord-twitter-webhooks
    env_file:
      - .env
    container_name: discord-twitter-webhooks
    environment:
      - WEBHOOK_URL=${WEBHOOK_URL}
      - BEARER_TOKEN=${BEARER_TOKEN}
      - RULE=${RULE}
      - ERROR_WEBHOOK=${ERROR_WEBHOOK}
      - SEND_ERRORS=${SEND_ERRORS}
      - LOG_LEVEL=${LOG_LEVEL}
    stop_grace_period: 30s
    restart: unless-stopped

and when I docker-compose up I got error they want to authen using access token and secret instead of bearer token
or anything missing in my docker-compose environment config ?

discord-twitter-webhooks    | 2023-03-23 at 10:13:05 DEBUG Failed to get a valid value for 'DISABLE_REMOVE_COPYRIGHT_SYMBOLS' which is set to ''. Defaulting to 'False'.
discord-twitter-webhooks    | Traceback (most recent call last):
discord-twitter-webhooks    |   File "/discord_twitter_webhooks/main.py", line 221, in <module>
discord-twitter-webhooks    |     start()
discord-twitter-webhooks    |   File "/discord_twitter_webhooks/main.py", line 217, in start
discord-twitter-webhooks    |     asyncio.run(start_bot())
discord-twitter-webhooks    |   File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
discord-twitter-webhooks    |     return runner.run(main)
discord-twitter-webhooks    |            ^^^^^^^^^^^^^^^^
discord-twitter-webhooks    |   File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
discord-twitter-webhooks    |     return self._loop.run_until_complete(task)
discord-twitter-webhooks    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
discord-twitter-webhooks    |   File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
discord-twitter-webhooks    |     return future.result()
discord-twitter-webhooks    |            ^^^^^^^^^^^^^^^
discord-twitter-webhooks    |   File "/discord_twitter_webhooks/main.py", line 170, in start_bot
discord-twitter-webhooks    |     await delete_old_rules(stream=stream)
discord-twitter-webhooks    |   File "/discord_twitter_webhooks/rules.py", line 23, in delete_old_rules
discord-twitter-webhooks    |     old_rules = await stream.get_rules()
discord-twitter-webhooks    |                 ^^^^^^^^^^^^^^^^^^^^^^^^
discord-twitter-webhooks    |   File "/opt/pysetup/.venv/lib/python3.11/site-packages/tweepy/asynchronous/streaming.py", line 720, in get_rules
discord-twitter-webhooks    |     return await self._make_request(
discord-twitter-webhooks    |            ^^^^^^^^^^^^^^^^^^^^^^^^^
discord-twitter-webhooks    |   File "/opt/pysetup/.venv/lib/python3.11/site-packages/tweepy/asynchronous/client.py", line 147, in _make_request
discord-twitter-webhooks    |     response = await self.request(method, route, params=request_params,
discord-twitter-webhooks    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
discord-twitter-webhooks    |   File "/opt/pysetup/.venv/lib/python3.11/site-packages/tweepy/asynchronous/client.py", line 118, in request
discord-twitter-webhooks    |     raise Forbidden(response, response_json=response_json)
discord-twitter-webhooks    | tweepy.errors.Forbidden: 403 Forbidden
discord-twitter-webhooks    | When authenticating requests to the Twitter API v2 endpoints, you must use keys and tokens from a Twitter developer App that is attached to a Project. You can create a project via the developer portal.
discord-twitter-webhooks exited with code 1
Originally created by @jedimage on GitHub (Mar 23, 2023). Original GitHub issue: https://github.com/TheLovinator1/discord-twitter-webhooks/issues/74 I've config my .env ``` WEBHOOK_URL=https://discord.com/api/webhooks/foo/bar BEARER_TOKEN=AAAAAAAAAAAAAAAAAAAAA RULE="(from:mytest_account)" ERROR_WEBHOOK=https://discord.com/api/webhooks/foo/bar SEND_ERRORS=True LOG_LEVEL=DEBUG ``` and config docker-compose to ``` version: "3" services: discord-twitter-webhooks: image: thelovinator/discord-twitter-webhooks env_file: - .env container_name: discord-twitter-webhooks environment: - WEBHOOK_URL=${WEBHOOK_URL} - BEARER_TOKEN=${BEARER_TOKEN} - RULE=${RULE} - ERROR_WEBHOOK=${ERROR_WEBHOOK} - SEND_ERRORS=${SEND_ERRORS} - LOG_LEVEL=${LOG_LEVEL} stop_grace_period: 30s restart: unless-stopped ``` and when I docker-compose up I got error they want to authen using access token and secret instead of bearer token or anything missing in my docker-compose environment config ? ``` discord-twitter-webhooks | 2023-03-23 at 10:13:05 DEBUG Failed to get a valid value for 'DISABLE_REMOVE_COPYRIGHT_SYMBOLS' which is set to ''. Defaulting to 'False'. discord-twitter-webhooks | Traceback (most recent call last): discord-twitter-webhooks | File "/discord_twitter_webhooks/main.py", line 221, in <module> discord-twitter-webhooks | start() discord-twitter-webhooks | File "/discord_twitter_webhooks/main.py", line 217, in start discord-twitter-webhooks | asyncio.run(start_bot()) discord-twitter-webhooks | File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run discord-twitter-webhooks | return runner.run(main) discord-twitter-webhooks | ^^^^^^^^^^^^^^^^ discord-twitter-webhooks | File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run discord-twitter-webhooks | return self._loop.run_until_complete(task) discord-twitter-webhooks | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ discord-twitter-webhooks | File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete discord-twitter-webhooks | return future.result() discord-twitter-webhooks | ^^^^^^^^^^^^^^^ discord-twitter-webhooks | File "/discord_twitter_webhooks/main.py", line 170, in start_bot discord-twitter-webhooks | await delete_old_rules(stream=stream) discord-twitter-webhooks | File "/discord_twitter_webhooks/rules.py", line 23, in delete_old_rules discord-twitter-webhooks | old_rules = await stream.get_rules() discord-twitter-webhooks | ^^^^^^^^^^^^^^^^^^^^^^^^ discord-twitter-webhooks | File "/opt/pysetup/.venv/lib/python3.11/site-packages/tweepy/asynchronous/streaming.py", line 720, in get_rules discord-twitter-webhooks | return await self._make_request( discord-twitter-webhooks | ^^^^^^^^^^^^^^^^^^^^^^^^^ discord-twitter-webhooks | File "/opt/pysetup/.venv/lib/python3.11/site-packages/tweepy/asynchronous/client.py", line 147, in _make_request discord-twitter-webhooks | response = await self.request(method, route, params=request_params, discord-twitter-webhooks | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ discord-twitter-webhooks | File "/opt/pysetup/.venv/lib/python3.11/site-packages/tweepy/asynchronous/client.py", line 118, in request discord-twitter-webhooks | raise Forbidden(response, response_json=response_json) discord-twitter-webhooks | tweepy.errors.Forbidden: 403 Forbidden discord-twitter-webhooks | When authenticating requests to the Twitter API v2 endpoints, you must use keys and tokens from a Twitter developer App that is attached to a Project. You can create a project via the developer portal. discord-twitter-webhooks exited with code 1 ```
Author
Owner

@TheLovinator1 commented on GitHub (Mar 23, 2023):

Hi,

Your key is for the v1 version of the API but my program is using v2, you need to create a new key on the Twitter Developer Portal for v2.

I think you have to create a new project here before you can use the v2 version.

<!-- gh-comment-id:1481371219 --> @TheLovinator1 commented on GitHub (Mar 23, 2023): Hi, Your key is for the v1 version of the API but my program is using v2, you need to create a new key on the [Twitter Developer Portal](https://developer.twitter.com/en/portal/dashboard) for v2. I think you have to create a new project [here](https://developer.twitter.com/en/portal/products) before you can use the v2 version.
Author
Owner

@jedimage commented on GitHub (Mar 23, 2023):

lol I'm just fix this before I have check your comment XD

sorry for inconvenience <3

<!-- gh-comment-id:1481403888 --> @jedimage commented on GitHub (Mar 23, 2023): lol I'm just fix this before I have check your comment XD sorry for inconvenience <3
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TheLovinator/discord-twitter-webhooks#10
No description provided.