「Twitter投稿」アプリを作ってみた
【開発環境】
os:Windows 10
IDE(統合開発環境):VisualStudio 2017
言語;VB
【参考書】
株式会社秀和システム「作って覚えるVisualBasic2017」
著者:萩原 博之/宮崎 昭世
【Twitter投稿アプリ】
デザイン画面

◆コントロールを貼る
①Button1コントロール
Button1.Text="Twitter投稿"
②TextBox1コントロール
③Button2コントロール
Button2.Text="PIN入力"
④TextBox2コントロール
TextBox2.Multiline="True"
⑤Button3コントロール
Button3.Text="ツイート"
追伸
Form1コントールのTextはTwitter投稿にしてね
【Twitter】
Twitter Developerの開発者申請とAPIキー取得方法について
【仮登録】
デジナビのTwitter Developerの開発者申請を参照にしてください
注意1) Internet Explorer 11では不具合が生じるよ。Chromeが良いかも
注意2)携帯電話が登録してないと、認証コードがSNSメールで送られて来ないよ
注意3)デジナビと違った点を下記に記す
1

2

3

4

5

この後はデジナビを参照のこと!
【本登録】
Twitterから届くメールを確認して本登録を完了
1

2

3確認したら、「create」ボタンを押す

4キー取得

◆CoreTweetのインストール
NUGetパッケージマネージャーを利用し、TwitterAPI を扱うためのライブラリCoreTweetをインストールする。
1.NUGetパッケージマネージャーを開く

2.NUGetパッケージマネージャー表示

3.検索ボックスに「CoreTweet」と入力し、該当プロジェクトにチェックし、「インストール」ボタンを押す

4.変更を確認するダイアログが表示されたら、「OK」ボタンをクリックする

【コーデング】
Public Class Form1
Private session As CoreTweet.OAuth.OAuthSession
Private Tokens As CoreTweet.Tokens
'twitterのアプリ認証
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'AIPキーとSecretキーをセットする
Dim AIP_key As String = "☓☓☓☓"
Dim Secret_key As String = "☓☓☓☓"
'アプリケーションの認証
session = CoreTweet.OAuth.Authorize(AIP_key, Secret_key)
'Pinコードの取得
Process.Start(session.AuthorizeUri.ToString())
End Sub
'Pin番号の入力
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Tokens = CoreTweet.OAuth.GetTokens(session, TextBox1.Text)
End Sub
'twitter投稿
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Tokens.Statuses.Update(TextBox2.Text)
End Sub
End Class
【twitter投稿アプリの操作】
1.操作画面の「twitter投稿」ボタンをクリックする

2.ブラウザーに「アカウントのアクセス許可をしますか」と表示される

3.PINコード表示
「連帯アプリを認証」ボタンをクリックすると

4.アプリにPINコードを入力し、「PIN入力」ボタンを押す

5.ツイート投稿

テキストに適当な文書を書いたら、「ツイート」ボタンをクリックする
6.結果

※コメント投稿者のブログIDはブログ作成者のみに通知されます