Question

As part of a mobile app I'm building I have to authenticate trough the API of Last.FM. As documented on their website I tried to format to url correctly but appearently I'm doing something wrong because I get error:

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: https://ws.audioscrobbler.com/2.0/?method=auth.getMobileSession

Last.FM documentation: http://www.last.fm/api/mobileauth

My code below:

            var username:String = "xxxxxxx";
            var password:String = "xxxxxxxxxxxx";

            var api_key:String = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
            var secret:String = "xxxxxxxxxxxxxxxxxxxxxx";

            var api_sig:String = MD5.hash( "api_key" + api_key + "methodauth.getMobileSessionpassword" + password + "username" + secret);

            var request:URLRequest = new URLRequest("https://ws.audioscrobbler.com/2.0/?method=auth.getMobileSession");
            var variables:URLVariables = new URLVariables();//create a variable container
            variables.username =username;
            variables.password = password;
            variables.api_key = api_key;
            variables.api_sig = api_sig;
            request.data = variables;
            request.method = URLRequestMethod.POST;//select the method as post/
            var loader:URLLoader = new URLLoader();
            loader.addEventListener(Event.COMPLETE, handleComplete);
            loader.load(request);//send the request with URLLoader()

Does someone know the answer?

Was it helpful?

Solution

Try to use HTTPService instead of URLLoader. Smth like this:

    var http:HTTPService = new HTTPService();
    http.useProxy = false;
    http.resultFormat = "e4x";
    http.method = "POST";
    http.url = "https://ws.audioscrobbler.com/2.0/?method=auth.getMobileSession";
    var variables:Object = {};
    variables.username = username;
    variables.password = password;
    variables.api_key = api_key;
    variables.api_sig = api_sig;

    var token:AsyncToken = http.send(variables);
    var responder:Responder = new Responder(handleRequestComplete, handleError);
    token.addResponder(responder);

Where handleRequestComplete and handleError are your handlers for the request results:

    private function handleRequestComplete(event:ResultEvent):void
    { 
        // your code here 
    }

    private function handleError(event:FaultEvent):void
    { 
        // your code here 
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top