homepage Welcome to WebmasterWorld Guest from 54.197.215.146
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Gathering, Interpreting & Using AdSense Earnings Information
A script to automate this process
otem




msg:3351233
 7:04 pm on May 27, 2007 (gmt 0)

I use my AdSense Earnings information to monitor my progress, supplement my internal reports and to enable me to perform certain performance calculations.

I gather my earnings information by hand to enter into a database on my website to perform most of these functions automatically based on scripts I have written.

Originially I had thought that there were only two ways to gather this information. One could log into the adsense website to read the earning reports and enter this information in by hand (manual and argious), or one could write a script to do the same (prohibited). Since the later could potentially get you banned, that only left me with one viable option.

That was until I had a realization that there was a second viable option. One is allowed to generate custom reports, and to have those reports emailed to them self daily.

In theory one could have their reports emailed to them by AdSense, and to write a script that would read the email reports and input this information into the database automatically. This option is not prohibited, and is complete automatic.

Therefore, I'm developing a script to automate the process of inputing adsense earnings and statistics data into a database on my website.

To start off, I'm working in a PHP and MySQL environment.

I started by setting up an email account with my hosting company that would write incoming emails to a non-public file on my server, "inbox.txt". Only emails to that specific address are affected.

Then, in the AdSense website, I setup a basic report of the previous day's earnings to have emailed to my specail email address daily.

AdSense sends out the reports in the morning (PST). The reports come in a .csv file that is then zipped and stored as an attachment.

I created a file that will read my inbox.txt file, to read the reports, and to grab the latest AdSense reports email:

<?php
$data=file_get_contents("inbox.txt");

preg_match_all("/filename=AdSense-Report\.csv\.zip(.*)------=_/Us",$data,$data);

$data=$data[1];
$last=count($data)-1;

$zip=base64_decode($data[$last]);

echo $zip;
?>

I'm now at a point where I'm stuck. I have the contents of the zip file, but I don't know how to read it.

My understanding is that PHP can not understand the contents of zip files without additional libraries. I don't know how to install these libraries. But I'm hoping that since this is such a small .zip file (only about 300 characters long) and that I'm only trying to read it, that I'm hoping installation of these libraries is over kill.

Once I get over the zip hurdle, I plan on adding to the script to where it will read the contents of the enclosed csv file, and that contents to the database, and to clear out the inbox.txt file.

I'm writing this post in hopes that others might find this script useful, and its information useful, and might join me in helping me over this hurdle. And maybe develop additional features for it.

 

eelixduppy




msg:3353432
 1:07 pm on May 30, 2007 (gmt 0)

You should be able to run an unzipping utility (varies based on your computer-might want to try unzip) from the command line using exec [php.net], or one of the similar functions. Once the file is in a readable format, you can search the info and update to your db.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved