Home > All, Flash/Flex/AIR > Phần II: Authentication (Working with Youtube In Flash/Flex)

Phần II: Authentication (Working with Youtube In Flash/Flex)

How To Get Auth Sub In Flash/Flex

private function getAuthentication() {

var getTokenPage : URLRequest = new URLRequest(‘https://www.google.com/accounts/AuthSubRequest’);
var urlPath: String = this.root.loaderInfo.url; // When logged on Google, user will redirect to return here.
var authSubParams : URLVariables = new URLVariables();
authSubParams[‘scope’] = ‘http://gdata.youtube.com/’; // youtube API
authSubParams[‘session’] = 0; // single-use token
authSubParams[‘secure’] = 0; // non-secure apps
authSubParams[‘next’] = urlPath; // The URL of this app.
getTokenPage.data =  authSubParams;
navigateToURL(getTokenPage, ‘_self’);

}

Clear old authentication and get new for long-live:

private function getLongLivedToken(singleUseToken : String) : void {

var getTokenRequest : URLRequest = new URLRequest(‘https://accounts.googleapis.com/accounts/AuthSubSessionToken’);
getTokenRequest.method = URLRequestMethod.POST;
getTokenRequest.data = new URLVariables(‘pleaseignore=ignore’);
getTokenRequest.requestHeaders.push(new URLRequestHeader(‘Authorization’, ‘AuthSub token=”‘ + singleUseToken + ‘”‘));
var getToken : URLLoader = new URLLoader();
getToken.addEventListener(Event.COMPLETE, completeLoadRequestHandler);
getToken.addEventListener(SecurityErrorEvent.SECURITY_ERROR, ioErrorHandler);
getToken.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
try {

getToken.load(getTokenRequest);

} catch (e : Error) {

trace(‘Some error occurred: ‘ + e);

}

}

Click here to view my demo http://www.swfcabin.com/swf-files/1268541186.swf

  1. 30/12/2013 at 9:55 pm

    If you are going for most excellent contents like I do, just go to see this web site everyday because it provides quality contents,
    thanks

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: