juust ~ php oddities

Unordered list of one element
  • rss
  • begin
  • about
    • vcard
    • WTF is BroJesus
  • php scripts
    • flickr wp widget
    • google multi key serp tool, php script
    • gwt plugin
  • php classes
    • php pagerank class
    • fibonacci class
    • robots.txt parser php class
  • serp
    • serp dashboard wordpress plugin
  • services

Tweets on Google’s frontpage

juust | 24/01/2010

The article about using Yahoo Pipes for Twitter ammo deserves an update. When I wrote it (june 2009), Google had not announced they would be listing Tweets on their frontpage.

I was curious if Google list tweets from an pipes account. The specific pipe does use Google News and other trusted news sources for it’s feed, so Tweets should rank high in relevance to the keyword, but I wasn’t sure Google allow automated accounts to hit the frontpage in Search.

I typed in “microfinance twitter” at Google Search and got this as result :

microfinance

There she is : @NeoFinance, one of my accounts that runs on a Yahoo Pipe.

The account itself is small, 750 tweets, it follows 60 accounts, and has 125 followers, mostly microfinance related. No automated following scripts, just the pipe. I had it offline for a few weeks but restarted it last week.

neofinance

Google do seem to consider Pipes-accounts acceptable.

         
Comments
No Comments »
Categories
google, seo
Comments rss Comments rss
Trackback Trackback

ga api sample : get pageviews

juust | 13/05/2009

I was going to put that online : how to get the pageviews out of the google analytics api, using simplexml and php. Google use three namespaces in the output file which make it less easy accessible, so here’s a quick sample of how to get your sites pageviews out of it :

  1. //ids           = site identifier (from the site data feed)
  2. //metrics     = what i want to see
  3. //start-date
  4. //end-date
  5.  
  6. $feedUri = "https://www.google.com/analytics/feeds/data?ids=ga:10516419&metrics=ga:pageviews&start-date=2009-04-01&end-date=2009-05-01";    
  7.  
  8.  $curl = curl_init();
  9.  curl_setopt($curl, CURLOPT_URL, $feedUri);
  10.  curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3);
  11.  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  12.  
  13.        $headers[] = "Authorization: GoogleLogin auth=".$Authtoken;
  14.  
  15. //for authtoken : see previous post
  16.  curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  17.  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
  18.  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  19.  curl_setopt($curl, CURLOPT_VERBOSE, 1);
  20.  
  21. //get the string containing the xml file
  22.  $gA = curl_exec($curl);

the feed has three namespaces (atom, opensearch and dxp/analytics), a simple way is accessing the ENTRY tags (from the Atom namespace), in that tag is one DXP: line and that has the answer to the question.

<dxp:metric confidenceInterval=’0.0′ name=’ga:pageviews’ type=’integer’ value=’755′/>

  1. //load the string into a simple xml object
  2.  $feed = simplexml_load_string($gA);
  3.  
  4. //take the atom namespace
  5.  $children =  $feed->children('http://www.w3.org/2005/Atom');
  6.  
  7. //take the entry tags
  8.  $parts = $children->entry;
  9.  foreach ($parts as $entry) {
  10.  
  11.         //from the entry tag,
  12.         //access the dxp namespace
  13.   $dxp = (object) $entry->children('http://schemas.google.com/analytics/2009');
  14.  
  15.         //METRIC contains the answer to the question
  16.         //grab from the tag METRIC the attribute VALUE
  17.                 echo   (string) $dxp->metric->attributes()->value;
  18.  
  19.         }

Important is using the (string) typecast, normally simplexml returns a simplexml object, when you force a string type, it gives the actual metric ga:pageview value attribute as number.

         
Comments
No Comments »
Categories
google, php
Tags
analytics, api, ga, google, namespaces, php, simplexml
Comments rss Comments rss
Trackback Trackback

google analytics have an api !

juust | 11/05/2009

[note: over at ioncannon Carson McDonald made a cool google analytics plugin for wordpress, i use it on this blog, works fine].

An actual google analytics api, and I missed out on it. This api is already a month old and i havent read anything on the blogs about it.

I found it half an hour ago, I havent checked it completely but it looks promising. Here is the first bit, basic authentication with php and curl.

  1. $USER_EMAIL=""; // #Insert your Google Account email here
  2. $USER_PASS=""; //#Insert your password here
  3.  
  4. //array with some general data
  5. $data = array(
  6.   "Email" => $USER_EMAIL,
  7.   "Passwd" => $USER_PASS,
  8.   "accountType" => "GOOGLE",
  9.   "source" => "curl-accountFeed-v1",
  10.   "service" => "analytics"
  11. );
  12.  
  13. $friends_url = 'https://www.google.com/accounts/ClientLogin';
  14. $curl = curl_init();
  15. curl_setopt($curl, CURLOPT_URL, $friends_url);
  16. curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3);
  17. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  18.  
  19. //http-post that contains the array as data
  20. curl_setopt($curl, CURLOPT_POST, true);
  21. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  22.  
  23. //go shove the https secure connection verification
  24. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
  25. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  26.  
  27. curl_setopt($curl, CURLOPT_VERBOSE, 1);
  28.    
  29.  
  30. $googleAuth = curl_exec($curl);
  31.  
  32. //optional : some feedback
  33.  
  34. //check if we get an error code from cUrl
  35. //    echo curl_errno($curl)."<br />";
  36. //    echo  curl_error($curl)."<br />" ;
  37.  
  38.  
  39. //print the body of the returned data
  40. //    print_r($googleAuth);
  41.  
  42. //print all the headers
  43. //    $info = curl_getinfo($curl);
  44. //    print_r($info);

somewhere in the garbled mess that curl returns is the Authorization token, starts with auth=.

  1. $start = strpos($googleAuth, "Auth=") + 5;
  2. $Authtoken = substr($googleAuth, $start);
  3.  
  4. //echo $Authtoken;

I put that token in the header of the next calls and google assumes I am kosher : time to get the accounts feed :

  1. //add the authoritzation token as extra header
  2. $headers[] = "Authorization: GoogleLogin auth=".$Authtoken;
  3.  
  4.  
  5. $friends_url = 'https://www.google.com/analytics/feeds/accounts/default';
  6.  
  7.  $curl = curl_init();
  8.  curl_setopt($curl, CURLOPT_URL, $friends_url);
  9.  curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3);
  10.  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  11.  curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  12.  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
  13.  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  14.  curl_setopt($curl, CURLOPT_VERBOSE, 1);
  15.  $googleAccounts = curl_exec($curl);
  16.  
  17. //check errors
  18. echo curl_errno($curl);
  19. echo curl_error($curl) ;
  20. print_r($googleAccounts);

And there it is : a whole list with weird codes, my account list :) seems easier than the other gData api’s.

note : the google code curl example does not show the ” auth=” part of the token, they assume you use the entire line “auth=…” as token.

Once I have my spectacular visitor count in a sidebar widget I’ll blog another post on this one.

         
Comments
No Comments »
Categories
google, php
Tags
analytics, api, curl, ga, google, php
Comments rss Comments rss
Trackback Trackback

« Previous Entries

Recent Posts

  • p2p with wordpress xml-rpc
  • Tweets on Google’s frontpage
  • happy new year
  • metaWeblog.newPost posting to Wordpress from Word
  • IE is retarded

click me!
rss
Comments rss
Blog Directory
Web Developement Blogs - BlogCatalog Blog Directory
Listed in LS Blogs the Blog Directory and Blog Search Engine
Blog Flux Directory
joopita.com free web directory and search engine
design by jide
sitemap
8076 confirmed spam kills