Twitter 인증 API를 이용하기 위한 Flex용 OAuth 라이브러리
- Posted at 2010/06/19 01:41
http://www.action-scripter.com/blog/trackback/1314
트위터 API를 이용하기 위해서는 크게 2가지로 Search와 REST를 이용할 수 있는데요.
각 API Methods를 이용할 때 인증없이 사용할 수 있는 명령과 인증이 필요한 명령이 있습니다.
당연히 계정을 이용한 API를 사용할 때는 인증이 필요한데요.
선 인증후 필요한 명령을 실행할 수 있는 형태로 인증이 필요한 API를 이용할 수 있습니다.
다만 Flickr처럼 명령을 호출할 때마다 인증키를 보내는 형태가 아닌 OAuth 인증방식을 통해 사용할 수 있습니다.
OAuth 인증방식에 대한 내용은 다음글을 통해 확인해보시고요.
Open API를 사용하기 위한 인증표준 OAuth, 트위터 2010년 10월부터 서드파티에 OAuth만 사용!!
Flex에서 인증이 필요한 트위터 API를 이용할 때는 coderanger.com에서 제작된 공개 라이브러리로 손쉽게 처리할 수 있습니다.
아래는 OAuth Class의 기본 사용방법입니다.
참고로 Flash 트위터 라이브러리는 blog.swfjunkie.com의 라이브러리가 최근까지 많이용되었는데요. OAuth 인증을 지원하지 않아서 인지는 모르지만 요즘은 SWX Twitter API를 가장 많이 사용하는 것 같습니다.
위에 소개한 라이브러리들은 트위터 개발 센터에서 ActionScript 라이브러리로 공식 소개되고 있는 것들입니다.
각 API Methods를 이용할 때 인증없이 사용할 수 있는 명령과 인증이 필요한 명령이 있습니다.
당연히 계정을 이용한 API를 사용할 때는 인증이 필요한데요.
선 인증후 필요한 명령을 실행할 수 있는 형태로 인증이 필요한 API를 이용할 수 있습니다.
다만 Flickr처럼 명령을 호출할 때마다 인증키를 보내는 형태가 아닌 OAuth 인증방식을 통해 사용할 수 있습니다.
OAuth 인증방식에 대한 내용은 다음글을 통해 확인해보시고요.
Open API를 사용하기 위한 인증표준 OAuth, 트위터 2010년 10월부터 서드파티에 OAuth만 사용!!
Flex에서 인증이 필요한 트위터 API를 이용할 때는 coderanger.com에서 제작된 공개 라이브러리로 손쉽게 처리할 수 있습니다.
아래는 OAuth Class의 기본 사용방법입니다.
(Flex에서 이용할 때 사용하는 방법으로 Flash에서 사용할 때는 약간의 튜닝이 필요합니다. ^^)
1) the actual request for authorisation:
2) future requests using saved authorisation tokens:
원문 : http://www.coderanger.com/blog/?p=59
OAuth Class : download
OAuth Twitter Example Class : download
private var _twitauth:OAuthManager = new OAuthManager();
_twitauth.addEventListener( OAuthEvent.ON_REQUEST_TOKEN_RECEIVED, onRequestTokenReceived );
_twitauth.addEventListener( OAuthEvent.ON_REQUEST_TOKEN_FAILED, onRequestTokenFailed );
_twitauth.addEventListener( OAuthEvent.ON_ACCESS_TOKEN_RECEIVED, onAccessTokenReceived );
_twitauth.addEventListener( OAuthEvent.ON_ACCESS_TOKEN_FAILED, onAccessTokenFailed );
_twitauth.usePinWorkflow = true;
_twitauth.consumerKey = key.text; // Your application key from your twitter.com settings page
_twitauth.consumerSecret = secret.text; // Your application secret from your twitter.com settings page
_twitauth.oauthDomain = "twitter.com";
_twitauth.requestToken();
// callback for "requestToken()" when request token received from twitter
private function onRequestTokenReceived( evt:OAuthEvent ):void
{
// This will redirect to a web page which allows users to accept and receive a pin number
// Normally might be best to display an alert warning user that they will get a web page
// displayed and what they should do with it
_twitauth.requestAuthorisation();
}
// call this method after getting the user to enter the pin number displayed on screen
private function onSendPin():void
{
if( pin.text.length != 7 )
{
Alert.show( "Sorry the PIN number is incorrect, it must be 7 numbers", "Approve Application", Alert.OK );
return;
}
if( !_twitauth.validatePin( pin.text ) )
{
Alert.show( "Sorry the PIN number is invalid and must have been typed incorrectly", "Approve Application", Alert.OK );
return;
}
_twitauth.requestAccessToken( Number( pin.text ) );
}
private function onAccessTokenReceived( evt:OAuthEvent ):void
{
// Store pins and tokens ready for future requests ... might even be good to confirm
// the customerName is what you were expected for this authorisation
accessPin = _twitauth.accessPin;
accessToken = _twitauth.accessToken;
accessTokenSecret = _twitauth.accessTokenSecret;
customerName = _twitauth.currentUserName;
// Now I can do my tweets and whatever
// ........
}
private var accessPin:Number;
private var accessToken:String;
private var accessTokenSecret:String;
private var customerName:String;
2) future requests using saved authorisation tokens:
var twitauth:OAuthManager = new OAuthManager(); twitauth.usePinWorkflow = true; // The following variables are retrieved from where there were stored when first authorised using step 1 twitauth.accessPin = accessPin; twitauth.accessToken = accessToken; twitauth.accessTokenSecret = accessTokenSecret; twitauth.consumerKey = applicationConsumerKey; twitauth.consumerSecret = applicationConsumerSecret; twitauth.oauthDomain = "twitter.com"; // Get our signed data using above keys, ready for sending to twitter var postData:String = twitauth.getSignedURI( "POST", "http://twitter.com/statuses/update.xml", "status=" + encodeURIComponent(tweet.text) ); // Setup our request to twitter using signed information var httpService:HTTPService = new HTTPService; httpService.url = "http://twitter.com/statuses/update.xml"; httpService.useProxy = false; httpService.method = "POST"; httpService.contentType = "application/x-www-form-urlencoded"; httpService.addEventListener( "result", httpPostResult ); httpService.addEventListener( "fault", httpPostFault ); httpService.send( new QueryString( postData ).toPostObject() );
원문 : http://www.coderanger.com/blog/?p=59
OAuth Class : download
OAuth Twitter Example Class : download
참고로 Flash 트위터 라이브러리는 blog.swfjunkie.com의 라이브러리가 최근까지 많이용되었는데요. OAuth 인증을 지원하지 않아서 인지는 모르지만 요즘은 SWX Twitter API를 가장 많이 사용하는 것 같습니다.
위에 소개한 라이브러리들은 트위터 개발 센터에서 ActionScript 라이브러리로 공식 소개되고 있는 것들입니다.
Comments List
-
oauth 에 대해서 서치하다가 또 여기로 들어왔네요 ㅋㅋ
이거 쉽지않네요 ㅋㅋ-
오.. 뭔가 재미있는거 만들고 있는건가?
아니면 학생들꺼? 크크. 트위터가 정책이 최근에 바뀌면서 상당히 까다롭게 바뀌었더라고.
나도 잘은 모르지만 예전 보다 좀 엄격하게 관리하는 것 같아.
-
-
Flash에서 사용하고 싶은데 어느부분을 수정해야하나요?
-
플래시에서 사용하시려면 http://apiwiki.twitter.com/w/page/22554675/SWX-Twitter-API 페이지에 있는 내용을 참고하시면됩니다.
-










