Upload
itsuki-kuroda
View
6.722
Download
1
Embed Size (px)
DESCRIPTION
下記リンクのアプリ開発で採用したiOSのTwitterFrameworkを使ってみた話です。ReverseAuthやTokenのMigrationについてです。 http://attacca.fm/posts/song/v1/f46aa5f217ced235abfb5073fc74582d
Citation preview
iOSのTwitterFrameworkを使ってみたら・・
@i2key
12年8月3日金曜日
Twitter4Jのほうが良かった。
12年8月3日金曜日
用途によってはね。
12年8月3日金曜日
Objective-C書いてる人どれくらいいます??
12年8月3日金曜日
自己紹介
12年8月3日金曜日
12年8月3日金曜日
@i2key<言語> Java屋 最近Objective-C
<仕事> ネット企業のR&D部門で サービス企画、開発
12年8月3日金曜日
ソーシャル音楽アプリAttacca
ミュージック(無料)最高2位(ノンプロモーション)
JASRAC許諾番号9010672028Y31018
12年8月3日金曜日
音楽は好きですか?
12年8月3日金曜日
普段、どんな音楽を聴いていますか?
12年8月3日金曜日
あなたのプレイリストは懐メロばかりになっていないですか?
12年8月3日金曜日
学生の頃に比べて明らかに新しい音楽に出会う機会が減っている
12年8月3日金曜日
h"p://jigokuno.img.jugem.jp/20090624_1292358.gif
毎日が忙しく、音楽に出会う場に行かなくなった
12年8月3日金曜日
h"p://jigokuno.img.jugem.jp/20090624_1292358.gif
毎日が忙しく、音楽に出会う番組を見なくなった
12年8月3日金曜日
時間が無いので、音楽に触れるのはオンラインばかり。しかし、オンラインでは能動的に動かないと好きな音楽にたどり着けない。
12年8月3日金曜日
音楽番組を見ていたときのような受動的な音楽の聴き方をしたい
12年8月3日金曜日
どうせ聴くなら、電車で隣に座っている知らない人が何を聴いてるかよりも
12年8月3日金曜日
知り合いが何を聴いているのかが気になる
12年8月3日金曜日
そんな想いを解決してくれます。そう、このAttaccaならね。
12年8月3日金曜日
http://attacca.fm/posts/song/v1/f46aa5f217ced235abfb5073fc74582d
12年8月3日金曜日
12年8月3日金曜日
12年8月3日金曜日
http://i2key.hateblo.jp/entry/playstudy3
刺激の欲しいあなた。今なら漏れなく、スリル感のある開発ができますよ!Play2.0ならね
12年8月3日金曜日
!!
!Dynamo!
DB!AWS!SDK�
Playframework!2.0�
���������
����
API!KEY� �
JVM�Apache!
JSON!
�����
contro
ller�
Manager�
APNS�
C2DM�
Amazon!Linux!(MTL!Amazon!Image)�
SSL!
Port
��!
TwiMer�
Model�
hMps�
Dynamo�HTML!
��������!(�����)�
������� OS� FW� FW�����
Manager�
Model�
12年8月3日金曜日
認証ツイート
プロフィール取得フレンドリストの取得
TwitterFramework
12年8月3日金曜日
iOS Twitter framework
12年8月3日金曜日
https://dev.twitter.com/docs/ios12年8月3日金曜日
iOS Twitter framework
Using the TweetSheetAPI requests with TWRequestUsing Reverse AuthMigrating tokens to System Accounts
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
TweetSheet
TWRequest
set
get
ACAcount
https://api.twitter.com/1/statuses/update
https://api.twitter.com/1/foo/bar
アカウント設定
ツイート
API直接コール
12年8月3日金曜日
Using the TweetSheet
iOS Twitter framework
12年8月3日金曜日
TweetSheet
iOS Twitter framework
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
TweetSheet
TWRequest
set
get
ACAcount
https://api.twitter.com/1/statuses/update
https://api.twitter.com/1/foo/bar
アカウント設定
ツイート
API直接コール
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
TweetSheet
TWRequest
set
get
ACAcount
https://api.twitter.com/1/statuses/update
https://api.twitter.com/1/foo/bar
アカウント設定
ツイート
API直接コール
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
TweetSheet
TWRequest
set
get
ACAcount
https://api.twitter.com/1/statuses/update
https://api.twitter.com/1/foo/bar
アカウント設定
ツイート
API直接コール
self.accountStore = [[ACAccountStore alloc] init];ACAccountType *twitterType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[self.accountStore requestAccessToAccountsWithType:twitterType withCompletionHandler: ^(BOOL granted, NSError *error) {! ! if (granted) {! ! ! //アクセス権を得た場合にやりたい処理! ! }}];
12年8月3日金曜日
if ([TWTweetComposeViewController canSendTweet]) { //やりたいこと! !}
アカウントが設定されていること
Using the TweetSheet
12年8月3日金曜日
Using the TweetSheet
- (void)showTweetSheet{ // Create an instance of the Tweet Sheet TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init]; // Set the initial body of the Tweet [tweetSheet setInitialText: @"♫RIVER / 10-FEET #attacca #nowplaying #music"]; // Presents the Tweet Sheet to the user [self presentViewController: tweetSheet animated:NO completion:^{ NSLog(@"Tweet sheet has been presented."); }];}
ツイートの入力画面の表示
12年8月3日金曜日
前述のチェック無しでもよいそうするとこんな画面になり
設定画面へ遷移出来る
Using the TweetSheet
12年8月3日金曜日
設定に飛ばすメソッドを用意して欲しい自前でやるには今まではURLSchemeで設定画面に飛ばすことは出来ていたが、iOS5.1で使えなくなった。TweetSheetのアルファを0にしてツイートシートを隠せばそれっぽく見えたけどやめといた
このダイアログはTweetSheetでだけ使える
しかたがないので、OAuthの自前のも残しておいた
Using the TweetSheet
12年8月3日金曜日
iOS Twitter framework
API requestswith TWRequest
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
TweetSheet
TWRequest
set
get
ACAcount
https://api.twitter.com/1/statuses/update
https://api.twitter.com/1/foo/bar
アカウント設定
ツイート
API直接コール
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
TweetSheet
TWRequest
set
get
ACAcount
https://api.twitter.com/1/statuses/update
https://api.twitter.com/1/foo/bar
アカウント設定
ツイート
API直接コール
NSDictionary *params //引数をkey,valueNSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/home_timeline.json"];TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:params requestMethod:TWRequestMethodPOST];
//----認証が必要なAPIを使う場合 START----ACAccountType *twitterType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];NSArray *accounts = [self.accountStore accountsWithAccountType:twitterType];[request setAccount:[accounts objectAtIndex:_twitterAccountIndex]];//----認証が必要なAPIを使う場合 END------
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {! if (!responseData || ((NSHTTPURLResponse*)response).statusCode >= 400) {! ! //エラー!!! } else {! ! NSString *responseStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];! ! //JSONの場合は、NSJSONSerializationとかでデシリアライズする! }}];
APIのURLを直接書く
JSONをデシリアライズする
認証済みアカウントを取り出してリクエストにセットする
12年8月3日金曜日
ややネイティブにTwitterAPIをコールするためのサポートクラス。
OAuth周りをAccountFrameworkと連携することで認証周りの処理を省くことが出来る。便利!
ややネイティブなので、APIのURLはむき出しで自分でリクエストを組み立てる感じ
twitterAPIは常に変化してるから、それには非依存にしたかったらしい12年8月3日金曜日
iOS Twitter framework
Using Reverse Auth
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
TWRequest
set
ACAcounthttps://api.twitter.com/1/foo/bar
アカウント設定
API直接コール
AttaccaAPI Server
Twitter APICall
(Twitter4J)
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
TWRequest
set
ACAcounthttps://api.twitter.com/1/foo/bar
アカウント設定
API直接コール
AttaccaAPI Server
Twitter APICall
(Twitter4J)API Server側もAccessTokenTokenSecret欲しい
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
TWRequest
set
ACAcounthttps://api.twitter.com/1/foo/bar
アカウント設定
API直接コール
AttaccaAPI Server
Twitter APICall
(Twitter4J)API Server側もAccessTokenTokenSecret欲しい
tokenやsecretをsetは出来るけど、getは出来ない隠蔽化されてる
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
TWRequest
set
ACAcounthttps://api.twitter.com/1/foo/bar
アカウント設定
API直接コール
AttaccaAPI Server
Twitter APICall
(Twitter4J)API Server側もAccessTokenTokenSecret欲しい
tokenやsecretをsetは出来るけど、getは出来ない隠蔽化されてる\(^o^)/
オワター12年8月3日金曜日
12年8月3日金曜日
12年8月3日金曜日
[email protected]にメールを送るReverse Auth使いたい!と英語で書く
12年8月3日金曜日
以下のようなテンプレメールが返ってくる(Reverse Authというワードで引っ掛けてる?)
Hello,
Thank you for your interest in Reverse Auth access.
This email is an automated response to acknowledge receipt of your email regarding Reverse Auth. A member of our team will review your request as soon as possible.
Our review will proceed much more quickly if you were to reply to this ticket with the following required information:
• Your App ID number (or consumer key) from https://dev.twitter.com/apps/ • A link to your application’s website • Links to screenshots of your application's user-facing Twitter functionality • Links to screenshots of your application in use
Please note that our ticketing system does not accept attachments, so you will need to upload your screenshots to your server or an image host and link to them in this ticket with full URLs (HTML is not supported).
If you have already provided the required information in your initial request, please respond to this ticket to affirm that the required information is present.
For your application to qualify for reverse auth access, it must be production-ready and built to work with Apple iOS5. Reverse Auth will not work with devices that do not use iOS 5.
We do not grant Reverse Auth for testing purposes, single-user applications, or for applications that are in the early stages of development.
If you are not requesting access to reverse auth and have received this response in error, please let us know by responding to this ticket.
If you have a technical question about the API, please visit our developer site, where you will find extensive documentation about the Twitter API: http://dev.twitter.com/doc
This ticket will be closed automatically if we do not receive a response from you within one week.
Thanks, Twitter API Policy
12年8月3日金曜日
以下の項目に回答する
>• Your App ID number (or consumer key) from https://dev.twitter.com/apps/Consumer Key is following For Puroduction use : EH1JqS85hK8cGdRXjao For Development use : hynOFqui0aPokaAAAZ6g
>• A link to your application’s website Sorry. This app is not yet launched. Launching is 28th June.
>• Links to screenshots of your application's user-facing Twitter functionality>• Links to screenshots of your application in use
http://hoge.com/foo/bar/reverseauth.pdf
12年8月3日金曜日
・多分自動返信なので、最初の1通目のメールは適当で良い (ReverseAuthという単語だけいれとけば。)・リリースしてない開発中のiPhoneアプリ・説明用のPRサイト等が無くてもOK・簡単な画面イメージとReverseAuthの用途を伝えた・申請開始から通るまで期間は大体20日くらい (知り合いの学生は1週間くらいだったらしい)・ReverseAuthの許可を得るコンシューマキーは 別に1つではなくてもよい 開発用と本番用の二つのコンシューマキーを ReverseAuth対応してもらえた
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
SingedRequest
TWRequest
set
ACAcount
アカウント設定
aaa
API直接コール
req
res
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
SingedRequest
TWRequest
set
ACAcount
https://api.twitter.com/1/statuses/update
https://api.twitter.com/1/foo/bar
アカウント設定
aaa
API直接コール
URL https://api.twitter.com/oauth/request_token
HTTP HEADER : Authorization OAuth oauth_timestamp="1343127155", oauth_nonce="74514FFF-274D-4AA0-84F5-X0FDDDB0801FA", oauth_version="1.0", oauth_consumer_key="AH1JqAAAAA85hK8cGdR9EPzA", oauth_signature_method="HMAC-SHA1", oauth_signature="G0CCHWVTIQn0aZwjYJay%2BjG%3F3FF%3D"
HTTP BODY : x_auth_mode=reverse_auth&
seancook : TWIOS5ReverseAuthExamplehttps://github.com/seancook
HTTP RESPONSE OAuth oauth_token="rc2qU1XTbZ7ehPUAqfvbaAA9PljaOd0keCk8UeImE", oauth_signature="rjhWzOAsnw20E8YbVJYDPAcRoASE%3D", oauth_consumer_key="AH1JqAAAAA85hK8cGdR9EPzA", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1343127155", oauth_version="1.0", oauth_nonce="umqOqVVBBABUACCb5wAoJRfhsNppsEBVHDB76I2jw"
req
res
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
SingedRequest
TWRequest
set
ACAcount
アカウント設定
aaa
API直接コール
req
res
res
URL https://api.twitter.com/oauth/access_token
HTTP HEADER : TWRequestにて認証するアカウント等は自動設定HTTP BODY : x_reverse_auth_parameters = "OAuth oauth_signature=\"fwBAOrD88DK22qUplAASAARX0Rq0%3D\", oauth_nonce=\"AkFRlWMIBPYP2ASASASAONAomQlF1XrFr2jsxFzMUFg\", oauth_version=\"1.0\", oauth_consumer_key=\"EH1JqS85hK8AAdAAAPzA\", oauth_token=\"KzLZRpY024AAAb4eBPRhB4Bt9i0UFJyW1vGcw\", oauth_timestamp=\"1343129483\", oauth_signature_method=\"HMAC-SHA1\""; x_reverse_auth_target = EH1JqS85hK8AAdAAAPzA;
HTTP RESPONSEoauth_token=60478457-3PK080ABCqHMTGlCBBlidbnGGyENw8abgDul9HTiEyI&oauth_token_secret=0M5671AdHTDOleyVarimoSuAS7CwNwJ1mFFA432SUIM&user_id=60478457&screen_name=i2key
12年8月3日金曜日
iOS Twitter framework
OAuth
iOS Twitter framework
ACAccount・username・token・secret
Account framework
SingedRequest
TWRequest
set
ACAcount
アカウント設定
aaa
API直接コール
req
res
res
URL https://api.twitter.com/oauth/access_token
HTTP HEADER : TWRequestにて認証するアカウント等は自動設定HTTP BODY : x_reverse_auth_parameters = "OAuth oauth_signature=\"fwBAOrD88DK22qUplAASAARX0Rq0%3D\", oauth_nonce=\"AkFRlWMIBPYP2ASASASAONAomQlF1XrFr2jsxFzMUFg\", oauth_version=\"1.0\", oauth_consumer_key=\"EH1JqS85hK8AAdAAAPzA\", oauth_token=\"KzLZRpY024AAAb4eBPRhB4Bt9i0UFJyW1vGcw\", oauth_timestamp=\"1343129483\", oauth_signature_method=\"HMAC-SHA1\""; x_reverse_auth_target = EH1JqS85hK8AAdAAAPzA;
HTTP RESPONSEoauth_token=60478457-3PK080ImqHMTGlqQlidbnGGyENw8abgDul9HTiEyI&oauth_token_secret=0M5mudKdHngTDOleyVarimoSuAS7CwNwJ1mFFNlSUIM&user_id=60478457&screen_name=i2key
SignedRequestのresponseそのまま
consumer_key
12年8月3日金曜日
- (void)reverseOauth {! // Step 1) Ask Twitter for a special request_token for reverse auth! NSURL *url = [NSURL URLWithString:TW_OAUTH_URL_REQUEST_TOKEN];!! // "reverse_auth" is a required parameter! NSDictionary *dict = [NSDictionary dictionaryWithObject:TW_X_AUTH_MODE_REVERSE_AUTH forKey:TW_X_AUTH_MODE_KEY];! TWSignedRequest *signedRequest = [[TWSignedRequest alloc] initWithURL:url parameters:dict requestMethod:TWSignedRequestMethodPOST];!! [self showProgress];! [signedRequest performRequestWithHandler:^(NSData *data, NSURLResponse *response, NSError *error) {! ! if (!data) {! ! ! [self dismissProgress:@"Error occurred in Step 1."];! ! }! ! else {! ! ! NSString *signedReverseAuthSignature = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];! ! !! ! ! // Step 2) Ask Twitter for the user's auth token and secret! ! ! // include x_reverse_auth_target=CK2 and x_reverse_auth_parameters=signedReverseAuthSignature parameters! ! ! dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{! ! ! ! NSDictionary *step2Params = [NSDictionary dictionaryWithObjectsAndKeys:[TWSignedRequest consumerKey], TW_X_AUTH_REVERSE_TARGET, signedReverseAuthSignature, TW_X_AUTH_REVERSE_PARMS, nil];! ! ! ! NSURL *authTokenURL = [NSURL URLWithString:TW_OAUTH_URL_AUTH_TOKEN];! ! ! ! TWRequest *step2Request = [[TWRequest alloc] initWithURL:authTokenURL parameters:step2Params requestMethod:TWRequestMethodPOST];! ! ! !! ! ! ! ACAccountType *twitterType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];! ! ! ! NSArray *accounts = [self.accountStore accountsWithAccountType:twitterType];! ! ! ! [step2Request setAccount:[accounts objectAtIndex:_twitterAccountIndex]];! ! ! ! [step2Request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {! ! ! ! ! if (!responseData || ((NSHTTPURLResponse*)response).statusCode >= 400) {! ! ! ! ! ! [self dismissProgress:@"Error occurred in Step 2."];! ! ! ! ! } else {! ! ! ! ! ! NSString *responseStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];! ! ! ! ! ! [[NSUserDefaults standardUserDefaults] setObject:responseStr forKey:@"authData"];! ! ! ! ! ! [self sendAuthData:responseStr loginWebView:nil];! ! ! ! ! }! ! ! ! }];! ! ! });! ! }! }];}
Reverse Authでアクセストークンを取得12年8月3日金曜日
iOS Twitter framework
Migrating tokensto system accounts
12年8月3日金曜日
iOS Twitter framework
OAuth(TwitterFramework未使用)
ACAccount・username・token・secret Account
framework
set
既存の認証済み情報・username・token・secret ...etc
iOS Twitter framework
TweetSheet
get
12年8月3日金曜日
iOS Twitter framework
OAuth(TwitterFramework未使用)
ACAccount・username・token・secret Account
framework
set
既存の認証済み情報・username・token・secret ...etc
iOS Twitter framework
TweetSheet
getself.accountStore = [[ACAccountStore alloc]init];ACAccountCredential *credential = [[ACAccountCredential alloc]initWithOAuthToken:token tokenSecret:tokenSecret];ACAccountType *twitterType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];ACAccount *account = [[ACAccount alloc]initWithAccountType:twitterType];account.credential = credential;[self.accountStore saveAccount:account withCompletionHandler:^(BOOL success, NSError *error) {! if (success) {! ! NSLog(@"saved account");! }}];
12年8月3日金曜日
まとめ
12年8月3日金曜日
iOSのTwitterFrameworkでAccessTokenを取得したい場合は、ReverseAuthの申請をすれば出来る。(大体20日程度、リリース前でも可能)
iOSのTwitterFrameworkでは 認証が凄く簡単!(設定画面で設定すれば認証完了) ツイートが凄く簡単! でも、それ以外はややネイティブ風なTWRequest (良く言うと柔軟、悪く言うとやることが多い。)
12年8月3日金曜日
Thank you :-)
12年8月3日金曜日