Twitter連携によってDMが読まれる不安を抱えている皆様へ
- 本家ができないなら TOBASIC! が制限すればいいじゃない
- TOBASIC! に OAuth2.0 風味の scope パラメータを2種類用意しました
- ダイレクトメッセージへのアクセスを制限したい
- アカウント情報へのアクセスのみに制限したい(http://dev.twitter.com/doc/get/account/verify_credentials など)
- おまけで state パラメータにも対応しています
- TOBASIC! に OAuth2.0 風味の scope パラメータを2種類用意しました
- サンプルスクリプトを PHP でご用意
<?php $username = $_GET['username']; $password = $_GET['password']; if ($password) { $home_timeline = file_get_contents("https://$username:$password@twitter-basicauth.appspot.com/1/statuses/home_timeline.xml"); $direct_messages = file_get_contents("https://$username:$password@twitter-basicauth.appspot.com/1/direct_messages.xml"); $verify_credentials = file_get_contents("https://$username:$password@twitter-basicauth.appspot.com/1/account/verify_credentials.xml"); } ?> <html> <head> <title>TOBASIC! sample</title> </head> <body> <a href="https://twitter-basicauth.appspot.com/oauth/authorize?consumer_key=SDCNLkvhJ0UZEAAUDK5zeg">authorize</a><br /> <a href="https://twitter-basicauth.appspot.com/oauth/authorize?consumer_key=SDCNLkvhJ0UZEAAUDK5zeg&scope=without_direct_messages">authorize(without_direct_messages)</a><br /> <a href="https://twitter-basicauth.appspot.com/oauth/authorize?consumer_key=SDCNLkvhJ0UZEAAUDK5zeg&scope=account">authorize(account)</a><br /> <? if ($home_timeline) { ?> <br /> home_timeline:<br /> <textarea cols="80" rows="40"><?= $home_timeline ?></textarea><br /> <? } ?> <? if ($direct_messages) { ?> <br /> direct_messages:<br /> <textarea cols="80" rows="40"><?= $direct_messages ?></textarea><br /> <? } ?> <? if ($verify_credentials) { ?> <br /> verify_credentials:<br /> <textarea cols="80" rows="40"><?= $verify_credentials ?></textarea><br /> <? } ?> </body> </html>
- 利用手順
- ユーザに認可させるための URL をブラウザで開く
https://twitter-basicauth.appspot.com/oauth/authorize?consumer_key=
&scope= &state=
-
-
- consumer key の登録と設定については後述
- scope は without_direct_messages(ダイレクトメッセージ以外)または account(アカウント情報のみ)
- state は callback にそのまま渡される任意の文字列
- 認可後、設定された callback URI にリダイレクトされるので username と password を受け取る
-
?username= &password= &state=
-
-
- callback の登録と設定については後述
- username と password は Basic 認証で使用する
-
- Twitter Application Management からコンシューマを登録し、自分の Consumer key と Consumer secret を取得
- 設定が必須な項目
- Application Type: Browser
- Callback URL: 上記の callback とは別物なので https://twitter-basicauth.appspot.com/oauth/verify を設定
- 設定が必須な項目
- 登録後、表示された Consumer key と Consumer secret を下記に保存してください
- https://twitter-basicauth.appspot.com/oauth/register
- callback は、サンプルスクリプトを例にすると https://ido.nu/ayaya/tobasic.php
- https やカスタム URI スキームのような盗聴の恐れがないものにしてください
- 空欄にすると認可後に http://f.hatena.ne.jp/asannou/20100830012735 のような画面になります
- callback は、サンプルスクリプトを例にすると https://ido.nu/ayaya/tobasic.php
- https://twitter-basicauth.appspot.com/oauth/register
- 既に TOBASIC! 対応版 Twitkit+ を使っている方で scope=without_direct_messages で認可 すると DM のタブをクリックしても、エラーとなって見れなくなることが確認できると思います
- もう一度 scope なしで認可 しなおせば、元に戻ります
- デメリット
- id:asannou にダイレクトメッセージを読まれる不安が残る