<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>zedia flash blog &#187; GData</title>
	<atom:link href="http://www.zedia.net/tag/gdata/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zedia.net</link>
	<description>Flash, ActionScript, SEO and everything in between</description>
	<lastBuildDate>Thu, 02 Feb 2012 17:58:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to connect to Google Analytics Data API in Flash</title>
		<link>http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-flash/</link>
		<comments>http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-flash/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 04:21:43 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[cURL]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[GData]]></category>
		<category><![CDATA[Google Analytics Data Api]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=424</guid>
		<description><![CDATA[In one of my previous post, I explained how to connect to Google Analytics Data API in AIR. The problem with that way of connecting was that it only worked in AIR. In Flash it works locally, but as soon as you put in on your web server it stops working. Not it is cool [...]]]></description>
			<content:encoded><![CDATA[<p>In one of my previous post, I explained <a title="How to connect to Google Analytics Data API in AIR" href="http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-air/" target="_self">how to connect to Google Analytics Data API in AIR</a>. The problem with that way of connecting was that it only worked in AIR. In Flash it works locally, but as soon as you put in on your web server it stops working. Not it is cool to build an AIR (desktop) application that pulls data from Google Analytics, but it would also be cool to build a web application that does the same thing. Well I found out how to do just that. It is a bit more complicated because it involves a bit of server side coding, in this case PHP.</p>
<p>How the process works is that first you login to Google Analytics, Google will then send you a token that you must use when asking for data. So we will have two simple PHP files; one to login in and one to ask for data.</p>
<p>The first one looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//this file is called get_token.php</span>
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span>user<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span>pass<span style="color: #009900;">&#93;</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'curl.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Curl<span style="color: #339933;">;</span>
<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$curl</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>post<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'https://www.google.com/accounts/ClientLogin'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>accountType <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;GOOGLE&quot;</span><span style="color: #339933;">,</span>  Email <span style="color: #339933;">=&gt;</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span> Passwd <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$pass</span><span style="color: #339933;">,</span> service <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;analytics&quot;</span><span style="color: #339933;">,</span> source <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;zedia-GAStats-0&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tempArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Auth=&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;root&gt;
	&lt;token&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tempArray</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/token&gt;
&lt;/root&gt;</pre></div></div>

<p>The second one looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//this file is called call_ga.php</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'curl.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;url&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$token</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;token&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$curl2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl2</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl2</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl2</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl2</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl2</span><span style="color: #339933;">,</span> CURLOPT_HTTPHEADER<span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Authorization: GoogleLogin auth='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$token</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$response2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>As you can see to make my calls to Google I am using the cURL library that is usually already installed on your server if you have PHP. Also for the get_token.php I am also using the <a title="Curl Class" href="http://github.com/shuber/curl/blob/ee9f201544f826ed909f7a149447cade6c92e587/curl.php" target="_blank">Curl class</a>, made by <a title="Sean Huber" href="http://huberry.com/blog" target="_blank">Sean Huber</a>, that just makes it easier to work with cURL.  Upload these files to your server. Now that we have the server side figured out, we can move on to the Flash part;  here it is:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoader</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLVariables</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> Sprite
<span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> loader:URLLoader;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _loader2:URLLoader;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _textField:<span style="color: #0066CC;">TextField</span>;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _token:<span style="color: #0066CC;">String</span>;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _buffer:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
  <span style="color: #66cc66;">&#123;</span>
    loader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, _onTokenLoaded, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #808080; font-style: italic;">//this call will load the token</span>
&nbsp;
    loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://www.YOUR_URL_WHERE_THE_PHP_RESIDE.net/get_token.php?user=YOUR_USERNAME&amp;pass=YOUR_PASSWORD&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    _textField = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    _textField.<span style="color: #0066CC;">height</span> = <span style="color: #cc66cc;">300</span>;
    _textField.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">300</span>;
    _textField.<span style="color: #0066CC;">multiline</span> = <span style="color: #000000; font-weight: bold;">true</span>;
    _textField.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;
    addChild<span style="color: #66cc66;">&#40;</span>_textField<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _onTokenLoaded<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> tempString:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>loader.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
    tempString = tempString.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, tempString.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">var</span> tempXML:<span style="color: #0066CC;">XML</span> = <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span>tempString<span style="color: #66cc66;">&#41;</span>;
    _token = tempXML.<span style="color: #006600;">token</span>;
&nbsp;
    _textField.<span style="color: #0066CC;">text</span> = _token;
&nbsp;
    _loader2 = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    _loader2.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, _onFeedLoaded, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> request:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://www.YOUR_URL_WHERE_THE_PHP_RESIDE.net/call_ga.php&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">var</span> urlVar:URLVariables = <span style="color: #000000; font-weight: bold;">new</span> URLVariables<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    urlVar.<span style="color: #006600;">token</span> = _token;
    urlVar.<span style="color: #0066CC;">url</span> = <span style="color: #ff0000;">&quot;https://www.google.com/analytics/feeds/accounts/default&quot;</span>;
    request.<span style="color: #0066CC;">data</span> = urlVar;
&nbsp;
    _loader2.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>request<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _onFeedLoaded<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    _textField.<span style="color: #0066CC;">text</span> = <span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#40;</span>_loader2.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
 <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>What you basically do is that you use your server to do all the communication between the Flash and Google. Everytime you will want a different feed to get different data you will call the call_ga.php file. It is that simple. If you have any question on this feel free to ask them in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-flash/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>How to connect to Google Analytics Data API in AIR</title>
		<link>http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-air/</link>
		<comments>http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-air/#comments</comments>
		<pubDate>Fri, 22 May 2009 03:37:38 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[as3corelib]]></category>
		<category><![CDATA[as3crypto]]></category>
		<category><![CDATA[as3httpclientlib]]></category>
		<category><![CDATA[GData]]></category>
		<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[Google Analytics Data Api]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=415</guid>
		<description><![CDATA[I had a bit of trouble doing just this a while ago, ended up trying many different ways and finally a reader of this blog, Nakamachi, gave me the solution. Because I think many of you are trying to connect to Google Analytics Data API ( or any Google APIs for that matters) I will [...]]]></description>
			<content:encoded><![CDATA[<p>I had a bit of trouble doing <a title="Connecting to Google Analytics Data Api using AS3; my failures" href="http://www.zedia.net/2009/connecting-to-google-analytics-data-api-using-as3-my-failures/" target="_self">just this a while ago</a>, ended up trying many different ways and finally a reader of this blog, <span class="info">Nakamachi, gave me the solution. Because I think many of you are trying to connect to Google Analytics Data API ( or any Google APIs for that matters) I will give you here my solution. My solution only works in AIR; I don&#8217;t know why, but as soon as I put it on the web, it stops working. I have found a solution for that problem too but I will keep it for another post.</span><br />
Here is how you can connect to GData:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> org.<span style="color: #006600;">httpclient</span>.<span style="color: #006600;">HttpClient</span>;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">net</span>.<span style="color: #006600;">URI</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">httpclient</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">HttpResponseEvent</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">httpclient</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">HttpRequestEvent</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">httpclient</span>.<span style="color: #006600;">HttpRequest</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">httpclient</span>.<span style="color: #006600;">http</span>.<span style="color: #0066CC;">Get</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">httpclient</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">HttpDataEvent</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> _firstBuffer:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
<span style="color: #000000; font-weight: bold;">var</span> _secondBuffer:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//this first connection will get the authorization token by sending the user name and password for Google Analytics</span>
<span style="color: #000000; font-weight: bold;">function</span> submitForm<span style="color: #66cc66;">&#40;</span>email:<span style="color: #0066CC;">String</span>, <span style="color: #0066CC;">password</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> client:HttpClient = <span style="color: #000000; font-weight: bold;">new</span> HttpClient<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">var</span> uri:URI = <span style="color: #000000; font-weight: bold;">new</span> URI<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;https://www.google.com/accounts/ClientLogin&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">var</span> variables:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">name</span>:<span style="color: #ff0000;">&quot;accountType&quot;</span>, value:<span style="color: #ff0000;">&quot;GOOGLE&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">name</span>:<span style="color: #ff0000;">&quot;Email&quot;</span>, value: email<span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">name</span>:<span style="color: #ff0000;">&quot;Passwd&quot;</span>, value: <span style="color: #0066CC;">password</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">name</span>:<span style="color: #ff0000;">&quot;service&quot;</span>, value: <span style="color: #ff0000;">&quot;analytics&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">name</span>:<span style="color: #ff0000;">&quot;source&quot;</span>, value: <span style="color: #ff0000;">&quot;your-application-identifier&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#93;</span>;
  client.<span style="color: #006600;">listener</span>.<span style="color: #0066CC;">onData</span> = _onFirstData;
  client.<span style="color: #006600;">listener</span>.<span style="color: #006600;">onComplete</span> = _onLoaderComplete;
  client.<span style="color: #006600;">postFormData</span><span style="color: #66cc66;">&#40;</span>uri, variables<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> _onFirstData<span style="color: #66cc66;">&#40;</span>event:HttpDataEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  _firstBuffer += event.<span style="color: #006600;">readUTFBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//this second connection will request information to GData</span>
<span style="color: #808080; font-style: italic;">//in this case account info for Google Analytics by</span>
<span style="color: #808080; font-style: italic;">//putting the auth token in the header of the request</span>
<span style="color: #000000; font-weight: bold;">function</span> _onLoaderComplete<span style="color: #66cc66;">&#40;</span>event:HttpResponseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> tempArray:<span style="color: #0066CC;">Array</span> = _firstBuffer.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Auth=&quot;</span><span style="color: #66cc66;">&#41;</span>;
 <span style="color: #000000; font-weight: bold;">var</span>  _authToken:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>tempArray<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> client:HttpClient = <span style="color: #000000; font-weight: bold;">new</span> HttpClient<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">var</span> uri:URI = <span style="color: #000000; font-weight: bold;">new</span> URI<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;https://www.google.com/analytics/feeds/accounts/default&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">var</span> request:HttpRequest = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Get</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  request.<span style="color: #006600;">addHeader</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Authorization&quot;</span>, <span style="color: #ff0000;">&quot;GoogleLogin auth=&quot;</span> + _authToken<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  client.<span style="color: #006600;">listener</span>.<span style="color: #0066CC;">onData</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>event:HttpDataEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    _secondBuffer += event.<span style="color: #006600;">readUTFBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
  client.<span style="color: #006600;">listener</span>.<span style="color: #006600;">onComplete</span> = _onSecondLoaderComplete;
  client.<span style="color: #006600;">request</span><span style="color: #66cc66;">&#40;</span>uri, request<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> _onSecondLoaderComplete<span style="color: #66cc66;">&#40;</span>event:HttpResponseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">trace</span> <span style="color: #66cc66;">&#40;</span>_secondBuffer<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>As you can see in order to circumvent the Authorization header restriction I am using the <a title="as3httpclientlib" href="http://code.google.com/p/as3httpclientlib/">as3httpclientlib</a> library which requires the <a title="as3corelib" href="http://code.google.com/p/as3corelib/" target="_blank">as3corelib</a> and <a title="as3crypto" href="http://code.google.com/p/as3crypto/" target="_blank">as3crypto</a> libraries to compile. Using the same principle you should be able to connect to Google APIs from your AIR application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-air/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

