JSn1nj4 / ElliotDerhay.com

My personal website project.
MIT License
0 stars 1 forks source link

Post to X/Twitter when publishing a post #135

Closed JSn1nj4 closed 9 months ago

JSn1nj4 commented 10 months ago

This should only happen on first publish, not subsequent. Will need OpenGraph tags and/or Twitter Card tags generated as well - separate issues.

JSn1nj4 commented 10 months ago

Currently unsure if should use OAuth 2.0 or Basic Auth. https://developer.twitter.com/en/docs/authentication/oauth-2-0/user-access-token

https://developer.twitter.com/en/docs/authentication/oauth-2-0/user-access-token#:~:text=authorize%20your%20App).-,Working%20with%20confidential%20clients,-If%20you%20are

  1. Posting as myself
  2. Not requesting auth for anyone else

If I go full OAuth 2.0 with PKCE, I'll have to...

  1. Request permissions and implement an OAuth flow
  2. Cache tokens correctly, including parsing the Cache-Control header for the right amount of time
  3. Automatically use the refresh-token when appropriate
  4. Probably notify myself (email and/or dashboard notice) when a reauth is needed
  5. Support re-authorization
  6. Properly "forget" the old authorization once it's expired
  7. Notify myself when auto-publishing fails due to expired auth
JSn1nj4 commented 10 months ago

Some other resources:

JSn1nj4 commented 9 months ago

Ended up going with this: https://github.com/noweh/twitter-api-v2-php

Well thought-out Twitter API client that supports both OAuth 1.1 and 2.0, depending on endpoints needed, and provides the rate-limiting headers back as well. Will be useful for caching and preventing hitting the API when not appropriate.