Contenu connexe Plus de Itsuki Kuroda (19) iOSのTwitterFrameworkを使ってみたら #twtr_hack1. iOSの
TwitterFramework
を使ってみたら・・
@i2key
12年8月3日金曜日
7. @i2key
<言語>
Java屋
最近Objective-C
<仕事>
ネット企業のR&D部門で
サービス企画、開発
12年8月3日金曜日
8. ソーシャル音楽アプリ
Attacca
ミュージック(無料)最高2位
(ノンプロモーション)
JASRAC許諾番号
12年8月3日金曜日
9010672028Y31018
12. 学生の頃に比べて
明らかに新しい音楽に
出会う機会が減っている
12年8月3日金曜日
14. 毎日が忙しく、
音楽に出会う番組を見なくなった
h"p://jigokuno.img.jugem.jp/20090624_1292358.gif
12年8月3日金曜日
17. どうせ聴くなら、
電車で隣に座っている知らない人が
何を聴いてるかよりも
12年8月3日金曜日
23. 刺激の欲しいあなた。今なら漏れなく、
スリル感のある開発ができますよ!Play2.0ならね
http://i2key.hateblo.jp/entry/playstudy3
12年8月3日金曜日
24. hMps API!KEY Manager TwiMer
APNS
contro Model
C2DM
ller
Port
!
SSL!
Manager !
JSON! !
!
Dynamo! Dyn
Model
DB! amo
HTML!
AWS!SDK
Playframework!2.0
Apache!
JVM
Amazon!Linux!(MTL!Amazon!Image)
! OS FW FW
( )
12年8月3日金曜日
25. 認証
ツイート
TwitterFramework
プロフィール取得
フレンドリストの取得
12年8月3日金曜日
28. iOS Twitter framework
Using the TweetSheet
API requests with TWRequest
Using Reverse Auth
Migrating tokens to System Accounts
12年8月3日金曜日
29. iOS Twitter framework
Account framework
ACAccount
・username
・token
・secret set
アカウント設定
OAuth
get
ツイート
Tweet https://api.twitter.com/1/statuses/update
Sheet Twitter
ACAcount
TWRequest https://api.twitter.com/1/foo/bar
API直接コール
iOS Twitter
framework
12年8月3日金曜日
32. iOS Twitter framework
Account framework
ACAccount
・username
・token
・secret set
アカウント設定
OAuth
get
ツイート
Tweet https://api.twitter.com/1/statuses/update
Sheet Twitter
ACAcount
TWRequest https://api.twitter.com/1/foo/bar
API直接コール
iOS Twitter
framework
12年8月3日金曜日
33. iOS Twitter framework
Account framework
ACAccount
・username
・token
・secret set
アカウント設定
OAuth
get
ツイート
Tweet https://api.twitter.com/1/statuses/update
Sheet Twitter
ACAcount
TWRequest https://api.twitter.com/1/foo/bar
API直接コール
iOS Twitter
framework
12年8月3日金曜日
34. iOS Twitter framework
Account framework
ACAccount
・username
・token
・secret set
アカウント設定
OAuth
get
ツイート
Tweet https://api.twitter.com/1/statuses/update
Sheet Twitter
self.accountStore = [[ACAccountStore alloc] init];
ACAccountType *twitterType = [self.accountStore
accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
ACAcount
TWRequest https://api.twitter.com/1/foo/bar
[self.accountStore requestAccessToAccountsWithType:twitterType
API直接コール withCompletionHandler:
^(BOOL granted, NSError *error) {
! !
! ! !
iOS Twitter
if (granted) {
//アクセス権を得た場合にやりたい処理
! ! }
}]; framework
12年8月3日金曜日
35. Using the TweetSheet
アカウントが設定されていること
if ([TWTweetComposeViewController canSendTweet]) {
//やりたいこと! !
}
12年8月3日金曜日
36. 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日金曜日
38. Using the TweetSheet
このダイアログは
TweetSheetでだけ使える
設定に飛ばすメソッドを用意して欲しい
自前でやるには今まではURLSchemeで設定画面に飛ばす
ことは出来ていたが、iOS5.1で使えなくなった。
TweetSheetのアルファを0にしてツイートシートを隠せば
それっぽく見えたけどやめといた
しかたがないので、
OAuthの自前のも残しておいた
12年8月3日金曜日
40. iOS Twitter framework
Account framework
ACAccount
・username
・token
・secret set
アカウント設定
OAuth
get
ツイート
Tweet https://api.twitter.com/1/statuses/update
Sheet Twitter
ACAcount
TWRequest https://api.twitter.com/1/foo/bar
API直接コール
iOS Twitter
framework
12年8月3日金曜日
41. iOS Twitter framework
NSDictionary *params //引数をkey,value
APIのURLを直接書く
Account framework
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/home_timeline.json"];
TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:params requestMethod:TWRequestMethodPOST];
ACAccount
//----認証が必要なAPIを使う場合 START----
・username
ACAccountType *twitterType = [self.accountStore
・token 認証済みアカウントを取り出して
accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
・secret set
NSArray *accounts = [self.accountStore accountsWithAccountType:twitterType]; リクエストにセットする
[request setAccount:[accounts objectAtIndex:_twitterAccountIndex]];
//----認証が必要なAPIを使う場合 END------
アカウント設定
OAuth
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
! if (!responseData || ((NSHTTPURLResponse*)response).statusCode >= 400) {
! ! //エラー!!
get
! } else {
! ! NSString *responseStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
! ! ツイート
Tweet
//JSONの場合は、NSJSONSerializationとかでデシリアライズする https://api.twitter.com/1/statuses/update
Twitter
! }
}];
JSONをデシリアライズする
Sheet
ACAcount
TWRequest https://api.twitter.com/1/foo/bar
API直接コール
iOS Twitter
framework
12年8月3日金曜日
44. iOS Twitter framework
Account framework
ACAccount
・username
・token
・secret set
アカウント設定
OAuth
ACAcount
TWRequest https://api.twitter.com/1/foo/bar
API直接コール Twitter
iOS Twitter
framework
Twitter API
Call
(Twitter4J)
Attacca
API Server
12年8月3日金曜日
45. iOS Twitter framework
Account framework
ACAccount
・username
・token
・secret set
アカウント設定
OAuth
ACAcount
TWRequest https://api.twitter.com/1/foo/bar
API直接コール Twitter
iOS Twitter
framework
Twitter API
API Server側も Call
(Twitter4J)
AccessToken
TokenSecret Attacca
欲しい API Server
12年8月3日金曜日
46. iOS Twitter framework
Account framework
tokenやsecretを
ACAccount
・username setは出来るけど、
・token
・secret set
getは出来ない
アカウント設定
隠蔽化されてる
OAuth
ACAcount
TWRequest https://api.twitter.com/1/foo/bar
API直接コール Twitter
iOS Twitter
framework
Twitter API
API Server側も Call
(Twitter4J)
AccessToken
TokenSecret Attacca
欲しい API Server
12年8月3日金曜日
47. iOS Twitter framework
Account framework
tokenやsecretを
ACAccount
・username setは出来るけど、
\(^o^)/
・token
・secret set
getは出来ない
アカウント設定
隠蔽化されてる
OAuth
ACAcount
TWRequest https://api.twitter.com/1/foo/bar
オワター
API直接コール Twitter
iOS Twitter
framework
Twitter API
API Server側も Call
(Twitter4J)
AccessToken
TokenSecret Attacca
欲しい API Server
12年8月3日金曜日
51. 以下のようなテンプレメールが返ってくる
(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日金曜日
52. 以下の項目に回答する
>• 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日金曜日
54. iOS Twitter framework
Account framework
ACAccount
・username
・token
・secret set
アカウント設定
OAuth
aaa
Singed req
Request res
Twitter
ACAcount
TWRequest
API直接コール
iOS Twitter
framework
12年8月3日金曜日
55. iOS Twitter framework
URL
https://api.twitter.com/oauth/request_token
HTTP HEADER : Authorization
Account framework
OAuth oauth_timestamp="1343127155",
oauth_nonce="74514FFF-274D-4AA0-84F5-X0FDDDB0801FA",
oauth_version="1.0",
oauth_consumer_key="AH1JqAAAAA85hK8cGdR9EPzA",
ACAccount
oauth_signature_method="HMAC-SHA1",
・username
・token
oauth_signature="G0CCHWVTIQn0aZwjYJay%2BjG%3F3FF%3D"
・secret set
HTTP BODY :
アカウント設定 x_auth_mode=reverse_auth&
OAuth
seancook : TWIOS5ReverseAuthExample
https://github.com/seancook
aaa
Singed req https://api.twitter.com/1/statuses/update
Request res
Twitter
HTTP RESPONSE
OAuth oauth_token="rc2qU1XTbZ7ehPUAqfvbaAA9PljaOd0keCk8UeImE",
ACAcount
oauth_signature="rjhWzOAsnw20E8YbVJYDPAcRoASE%3D",
TWRequest https://api.twitter.com/1/foo/bar
oauth_consumer_key="AH1JqAAAAA85hK8cGdR9EPzA",
oauth_signature_method="HMAC-SHA1",
API直接コール
oauth_timestamp="1343127155",
iOS Twitter
oauth_version="1.0",
oauth_nonce="umqOqVVBBABUACCb5wAoJRfhsNppsEBVHDB76I2jw"
framework
12年8月3日金曜日
56. iOS Twitter framework
Account framework
URL
ACAccount
https://api.twitter.com/oauth/access_token
・username
・token
・secret set
HTTP HEADER :
TWRequestにて認証するアカウント等は自動設定
アカウント設定
HTTP BODY :
OAuth
x_reverse_auth_parameters = "OAuth
oauth_signature="fwBAOrD88DK22qUplAASAARX0Rq0%3D
", oauth_nonce=
"AkFRlWMIBPYP2ASASASAONAomQlF1XrFr2jsxFzMUFg",
aaa oauth_version="1.0", oauth_consumer_key=
Singed req
"EH1JqS85hK8AAdAAAPzA", oauth_token=
Request res oauth_timestamp="1343129483",
Twitter
"KzLZRpY024AAAb4eBPRhB4Bt9i0UFJyW1vGcw",
oauth_signature_method="HMAC-SHA1"";
x_reverse_auth_target = EH1JqS85hK8AAdAAAPzA;
ACAcount
TWRequest
API直接コール
res
iOS Twitter
HTTP RESPONSE
oauth_token=60478457-3PK080ABCqHMTGlCBBlidbnGGyEN
w8abgDul9HTiEyI&oauth_token_secret=0M5671AdHTDOle
framework
yVarimoSuAS7CwNwJ1mFFA432SUIM&user_id=60478457&sc
reen_name=i2key
12年8月3日金曜日
57. iOS Twitter framework
Account framework
URL
ACAccount
https://api.twitter.com/oauth/access_token
・username
・token
・secret set
HTTP HEADER :
TWRequestにて認証するアカウント等は自動設定
アカウント設定
HTTP BODY :
OAuth
x_reverse_auth_parameters = "OAuth
oauth_signature="fwBAOrD88DK22qUplAASAARX0Rq0%3D
", oauth_nonce=
aaa
SignedRequestの
"AkFRlWMIBPYP2ASASASAONAomQlF1XrFr2jsxFzMUFg",
oauth_version="1.0", oauth_consumer_key=
Singed req
responseそのまま
"EH1JqS85hK8AAdAAAPzA", oauth_token=
Request res
Twitter
"KzLZRpY024AAAb4eBPRhB4Bt9i0UFJyW1vGcw",
oauth_timestamp="1343129483",
oauth_signature_method="HMAC-SHA1"";
x_reverse_auth_target = EH1JqS85hK8AAdAAAPzA;
ACAcount
consumer_key
TWRequest
API直接コール
res
iOS Twitter
HTTP RESPONSE
oauth_token=60478457-3PK080ImqHMTGlqQlidbnGGyENw8
abgDul9HTiEyI&oauth_token_secret=0M5mudKdHngTDOle
framework
yVarimoSuAS7CwNwJ1mFFNlSUIM&user_id=60478457&scre
en_name=i2key
12年8月3日金曜日
58. - (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日金曜日
60. iOS Twitter framework
OAuth
(TwitterFramework未使用)
既存の認証済み情報
・username
・token
・secret ...etc
set
ACAccount
・username
・token
・secret
Account Twitter
framework
get
Tweet
Sheet
iOS Twitter
framework
12年8月3日金曜日
61. iOS Twitter framework
OAuth
(TwitterFramework未使用)
既存の認証済み情報
・username
・token
・secret ...etc
set
ACAccount
・username
・token
・secret
Account Twitter
framework
self.accountStore = [[ACAccountStore alloc]init]; get
ACAccountCredential *credential = [[ACAccountCredential alloc]initWithOAuthToken:token tokenSecret:tokenSecret];
ACAccountType *twitterType = [self.accountStore
Tweet
accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
ACAccount *account = [[ACAccount alloc]initWithAccountType:twitterType];
account.credential = credential;
Sheet
[self.accountStore saveAccount:account withCompletionHandler:^(BOOL success, NSError *error) {
! if (success) {
! ! NSLog(@"saved account");
! }
}];
iOS Twitter
framework
12年8月3日金曜日