Add Tweets to My Blog
Browser Side¶
In [ ]:
cat hexo/themes/freemind/_config.yml
In [ ]:
cat hexo/themes/freemind/layout/_widget/links.ejs
In [ ]:
cat hexo/themes/freemind/source/js/twitter.js
- Here is all the changes at the browser side.
Server Side¶
- Here is a solution using Flask to proxy Tweets API.
In [ ]:
BEARER_TOKEN=''
In [ ]:
curl -H "Authorization: Bearer ${BEARER_TOKEN}" 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=seii_saintway&count=20'
In [ ]:
curl -H "Authorization: Bearer ${BEARER_TOKEN}" 'https://api.twitter.com/2/users/807092313298112512/tweets?tweet.fields=created_at&max_results=10'
- My solution using Traefik to proxy Tweets API
In [ ]:
cat << EOF | sudo tee /opt/tljh/state/dynamic/tweets.toml > /dev/null
[frontends.tweets]
backend = "tweets"
[frontends.tweets.routes.r1]
rule = "PathPrefix:/tweets/"
[frontends.tweets.routes.r2]
rule = "ReplacePath:/2/users/807092313298112512/tweets"
[frontends.tweets.headers.customrequestheaders]
Authorization = "Bearer ${BEARER_TOKEN}"
[frontends.tweets.headers.customresponseheaders]
Access-Control-Allow-Origin = "*"
[backends.tweets.servers.s1]
url = "https://api.twitter.com"
weight = 1
EOF
In [ ]:
sudo systemctl restart traefik
In [ ]:
curl 'https://jhub.name/tweets/?tweet.fields=created_at&max_results=10'