0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GitHub Actionsからツイートできるtwitter-togetherを使ってみる

Posted at

概要

twitter-togetherはGitHubリポジトリに作成したtweetファイルをGitHub Actionsを通してツイートしてくれる。GitHub Actionです。

使い方

1.Twitter Developerでappの作成

Twitter DeveloperのリンクからTwitterログインをしてappを作成してConsumer API keysとAccess token & access token secretを取得できる状態にしてください。

2.プロジェクトの作成

プロジェクト作成といってもGitHub Actions用のymlを用意するだけです。
今回はお試しなので、Readmeに記載されているものをそのまま使います。

.github/workflows/twitter-together.yml

on: [push, pull_request]
name: Twitter, together!
jobs:
  preview:
    name: Preview
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request'
    steps:
      - uses: gr2m/twitter-together@v1.x
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  tweet:
    name: Tweet
    runs-on: ubuntu-latest
    if: github.event_name == 'push' && github.ref == 'refs/heads/master'
    steps:
      - name: checkout master
        uses: actions/checkout@v2
      - name: Tweet
        uses: gr2m/twitter-together@v1.x
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }}
          TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
          TWITTER_API_KEY: ${{ secrets.TWITTER_API_KEY }}
          TWITTER_API_SECRET_KEY: ${{ secrets.TWITTER_API_SECRET_KEY }}

3.リポジトリ作成とpush

GitHubにログイン後、New repositoryからリポジトリを作成。

作成後、プロジェクトと紐づけてpush

git remote add origin https://github.com.....
git branch -M master
git push -u origin master

これでプロジェクトの設定は完了。

ちなみに、pushした段階でtwitter-togetherからPRが追加されるのでこちらもmergeしちゃいましょう。 mergeするとtweets/デイレクトリが作成されます。このディレクトリにツイートしたい内容のファイルを格納していきます。

twitter-together.png

4.リポジトリの環境変数の設定

作成したGitHubのリポジトリからSettingsSecretsNew secretからtwitter-togetherで使う環境変数を設定してください。この時に使う値はさきほどTwitter Developerで作成していただいた、API_KEYなどです。

設定するKEY項目 ※GITHUB_TOKENは設定しなくて大丈夫です。

TWITTER_API_KEY
TWITTER_API_SECRET_KEY
TWITTER_ACCESS_TOKEN
TWITTER_ACCESS_TOKEN_SECRET

5.tweetファイルを追加してツイートする

リポジトリからtweetsフォルダをクリックして右上のAdd fileからtweetファイルを作成してみましょう。ローカルからだとめんどくさいので

Create new file

ファイル名はtogether-first.tweetに設定

together-first

ファイル内容は以下の内容に設定

スクリーンショット 2020-10-23 11.55.08.png

下のほうにあるコミット設定はそのままで、Commit new fileボタンをクリック。

コミットが完了するとGitHub Actionが動き出し成功すればGreenのチェックマークになります。

github-action

連携してるTwitterを確認しツイート出来てればokです。

最後に

コミュニティのTwitterアカウントやOSSのアカウントなど持っている方は宣伝等のツイートで使ってみるといい感じになるかもしれません。

参考資料

GitHub twitter-together

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?