Translating CURL to FLEX HTTPRequests
- by Joshua
I am trying to convert from some CURL code to FLEX/ActionScript.
Since I am 100% ignorant about CURL and 50% ignorant about Flex and 90% ignorant on HTTP in general...
I'm having some significant difficulty.
The following CURL code is from http://code.google.com/p/ga-api-http-samples/source/browse/trunk/src/v2/accountFeed.sh
I have every reason to believe that it's working correctly.
USER_EMAIL="[email protected]" #Insert your Google Account email here
USER_PASS="secretpass" #Insert your password here
googleAuth="$(curl https://www.google.com/accounts/ClientLogin -s \
-d Email=$USER_EMAIL \
-d Passwd=$USER_PASS \
-d accountType=GOOGLE \
-d source=curl-accountFeed-v2 \
-d service=analytics \
| awk /Auth=.*/)"
feedUri="https://www.google.com/analytics/feeds/accounts/default\
?prettyprint=true"
curl $feedUri --silent \
--header "Authorization: GoogleLogin $googleAuth" \
--header "GData-Version: 2"
The following is my abortive attempt to translate the above CURL to AS3
var request:URLRequest=new URLRequest("https://www.google.com/analytics/feeds/accounts/default");
request.method=URLRequestMethod.POST;
var GoogleAuth:String="$(curl https://www.google.com/accounts/ClientLogin -s " +
"-d [email protected] " +
"-d Passwd=secretpass " +
"-d accountType=GOOGLE " +
"-d source=curl-accountFeed-v2" +
"-d service=analytics " +
"| awk /Auth=.*/)";
request.requestHeaders.push(new URLRequestHeader("Authorization", "GoogleLogin " + GoogleAuth));
request.requestHeaders.push(new URLRequestHeader("GData-Version", "2"));
var loader:URLLoader=new URLLoader();
loader.dataFormat=URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, GACompleteHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, GAErrorHandler);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, GAErrorHandler);
loader.load(request);
This probably provides you all with a good laugh, and that's okay, but if you can find any pity on me, please let me know what I'm missing. I readily admit functional ineptitude, therefore letting me know how stupid I am is optional.