1
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.

【Twitter API】シェアボタンを設置

Posted at

はじめに#

 ポートフォリオにTwitterのシェアボタンを付けたくてやってみましたので、備忘録として残しておきます。
これ自体は簡単ですがAPIの申請がなかなかハードル高かったです・・・。

Twitterシェアボタンの実装方法#

①下記URLのページへ遷移
https://publish.twitter.com/#

②Twitter Buttonsを選択
少し下にスクロールすると、このような画面が出てきます。
一番右のTwitter Buttonsを選択しましょう。
スクリーンショット 2021-10-02 21.34.33.png

③Share Buttonを選択
するとこのようなポップアップが出てきます。
一番左のShare Buttonを選択します。
スクリーンショット 2021-10-02 21.35.53.png

④コードをコピー
するとこのような画面が出てきます。コードをコピーすればあとは貼り付けるだけです!
スクリーンショット 2021-10-02 21.36.59.png

twitter.html
<a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" data-show-count="false">Tweet</a>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

こんな感じになります。
簡単ですね!

カスタマイズ#

 ツイートの内容をカスタマイズするにはaタグに属性を追加します。

・data-text="テキスト" ・・・  ツイートに表示するテキストを設定。
・data-hashtags="ハッシュタグ" ・・・  ツイートに表示するハッシュタグを設定。
・data-size="large" = ボタンサイズを大きくします。
  
これらの属性を加えることでツイートの内容をカスタマイズできます。
他にも色々種類があるのでやってみましょう!

1
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
1
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?