0

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?

user683326
  • 39
  • 5
  • Does that error come from Flex? Or from the Last.FM API? At what point do you see the error? – JeffryHouser Nov 10 '13 at 14:26
  • From FLEX is says that the fault is on line 59, which in this piece of code is " var loader:URLLoader = new URLLoader();" – user683326 Nov 10 '13 at 14:32
  • It seems highly unusual you would get a "unhandled ioError" on a line that just creates a new instance of a URLLoader class. Have you added a listener to the ioError event of URLLoader? http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html#event:ioError It may give you more insight. – JeffryHouser Nov 10 '13 at 14:38
  • I just did it but I get pretty much the same message in my console Error #2032: Stream Error. URL: https://ws.audioscrobbler.com/2.0/?method=auth.getMobileSession – user683326 Nov 10 '13 at 14:52

1 Answers1

0

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 
    }
tensorcrow
  • 68
  • 5
  • I was under the impression that HTTPService uses a URLLoader under the hood; as such I'm not sure why this would avoid the errors. – JeffryHouser Nov 11 '13 at 11:52