Forum Moderators: martinibuster

Message Too Old, No Replies

AdSense totals sent via SMS to cellphone

         

JohnKelly

1:03 am on Feb 23, 2005 (gmt 0)

10+ Year Member



When I'm out of town I'd like to be able to receive updates on my cellphone on AdSense totals.

There are a couple of scripts I've found, but one no longer works and the other requires Adsense Monitor installed.

I just need a basic (PHP preferred) script to securely login to my AdSense account and email the daily total to me SMS-enabled cellphone.

Does anyone know of a working script, and is this okay with the TOS?

hwyking

3:48 am on Feb 23, 2005 (gmt 0)

10+ Year Member



I got this from another member on here.
I set up a cron job to email me my earnings at the 55th minute of every hour. I heard google doesn't gave a problem if you don't log in to your account more than once every 15 minutes.

<?
$username="uername@email.com";
$password="pass";
$cookie="/mywebsite.com/adsense/cookiefile";
$log="/mywebsite.com/adsense/adsense.log.txt";
$destination="/adsense/reports-aggregate?product=afc&dateRange.dateRangeType=simple&dateRange.simpleDate=today";

$postdata="destination=".urlencode($destination)."&username=".urlencode($username)."&password=".urlencode($password)."&null=Login";

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,"https://www.google.com/adsense/login.do");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt ($ch, CURLOPT_TIMEOUT, 20);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close($ch);

preg_match('/\<tr class\="totals"\>.*\<td.*\>.*\<\/td\>.*\<td.*\>(.*)\<\/td\>.*\<td.*\>(.*)\<\/td\>.*\<td.*\>(.*)\<\/td\>.*\<td.*\>(.*)\<\/td\>.*\<td.*\>(.*)\<\/td\>.*<\/tr>/simU', $result, $array);
foreach ($array as $key => $value) {$array[$key] = trim($value, "\x22\x27\n\r ");} // strip $ % , here if desired
list($full,$Impressions,$Clicks,$Rate,$CPM,$Earnings) = $array;

putenv('TZ=US/Pacific'); // match Google time no matter where you or your serverlive
$output=date("Y-m-d H:i:s")." \t ".$Impressions." \t ".$Clicks." \t ".$Rate." \t".$CPM." \t ".$Earnings."\r\n";
if ($handle = fopen($log, 'a')) {fwrite($handle, $output); fclose($handle);} else {echo "error writing";}

//mail("5555555555@mobile.att.net", "Adsense report", $output, "From: Adsense");
mail("myemail@email.com", "Adsense report", $output, "From: Adsense");
?>

JohnKelly

3:50 am on Feb 23, 2005 (gmt 0)

10+ Year Member



Just what I needed, many thanks!

neiq

6:23 am on Feb 23, 2005 (gmt 0)

10+ Year Member



Hi. I was wondering if any one has seen this before? How does this work? Does google allow this?

[edited by: Jenstar at 7:06 am (utc) on Feb. 23, 2005]
[edit reason] Added to the discussion on this script [/edit]

tamen

8:46 am on Feb 23, 2005 (gmt 0)

10+ Year Member



It works and Google allow it. I have mailed with G. about it and the only thing they said was to be careful not to make the stats public, which would make you break the TOS.

I have this script, modified a bit, running every 20 minutes as a command in Geektool [projects.tynsoe.org]. So I have a small part of my desktop always showing todays, yesterdays, this months, last months and total earnings.

neiq

1:25 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



What needs to be changed in the code to get it to work? Also how do I get it to show todays, yesterdays, this months, last months and total earnings

frox

2:07 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



What needs to be changed:

At the beginning
$username="uername@email.com";
$password="pass";
replace with your username and passeord

$cookie="/mywebsite.com/adsense/cookiefile";
$log="/mywebsite.com/adsense/adsense.log.txt";
path (not URL) of two files that must be writable by the php script.
easiest thing that will 99% of times work is to just have:
$cookie="cookiefile";
$log="adsense.log.txt";
The two files will have to be in the same directory where you keep the script.
create two empty files, upload them (e.g. via FTP) and then chmod them to writable

mail("myemail@email.com", ....
put your email address here

this should work!
nice script, thanks to the OP!

amznVibe

2:13 pm on Feb 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nice to see my script being used for such helpful things.
The original thread is here if anyone wants to see other modifications and add-ons:
[webmasterworld.com...]

frox

2:19 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



So, amznVibe, the OP is you.
thanks, nice thing to play with!

tamen

9:22 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



Here is my modified copy of the code:

<?
$today = 'today';
$yesterday = 'yesterday';
$thismonth = 'thismonth';
$lastmonth = 'lastmonth';
$total = 'alltime';

$html = "\n Google Adsense:\n";
$html .= ' Today: '.getUSD($today)."\n";
$html .= ' Yesterday: '.getUSD($yesterday)."\n";
$html .= ' This month: '.getUSD($thismonth)."\n";
$html .= ' Last month: '.getUSD($lastmonth)."\n";
$html .= ' Total: '.getUSD($total)."\n";

echo $html;

function getUSD($url)
{
$username = 'username'; // change this
$password = 'password'; // and this
$cookie = 'cookiefile';
$destination = '/adsense/reports-aggregate?product=afc&dateRange.dateRangeType=simple&dateRange.simpleDate='.$url;

$postdata = 'destination='.urlencode($destination).'&username='.urlencode($username).'&password='.urlencode($password).'&null=Login';

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,"https://www.google.com/adsense/login.do");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt ($ch, CURLOPT_TIMEOUT, 20);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close($ch);

preg_match('/USD ([0-9,^<]*) <\/td> <\/tr> <tr class="averages">/', $result, $match);
return $match[1];
}
?>

This will output something like:

Google Adsense:
Today: xx,xx
Yesterday: xx,xx
This month: xx,xx
Last month: xx,xx
Total: xx,xx

Remember to change your username and password.

kempozone

9:36 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



Ahem.... I don't mean to be so ignorant:( but can anyone walk me through to how i can set up the code ... in layman's term.

thanks
kz

nosense

9:55 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



Sticky me if your good with VB script. I had a script with SMS working, but some code changed. It needs a little work, but probably could be fixed in under an hour.

dcmginc

11:09 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



Has anyone had any luck setting up a cron job? I copied the code and made a file... adsense.php and put it into the /adsense directory on my site. If I enter the web address to my adsense.php it loads up and sends me a message to my phone. I've been trying to setup the cron job so that it does it a couple of times a day.

I've tried everything but I'm getting a bunch of different responses each time. The last attempt gave me this:

/home/dcmg/public_html/adsense/adsense.php: line 1:?: No such file or directory
/home/dcmg/public_html/adsense/adsense.php: line 2: =<username removed>: command not found
/home/dcmg/public_html/adsense/adsense.php: line 3: =<password removed>: command not found
/home/dcmg/public_html/adsense/adsense.php: line 4: =cookiefile: command not found
/home/dcmg/public_html/adsense/adsense.php: line 5: =adsense.log.txt: command not found
/home/dcmg/public_html/adsense/adsense.php: line 6: =/adsense/reports-aggregate?product=afc&dateRange.dateRangeType=simple&dateRange.simpleDate=today: No such file or directory
/home/dcmg/public_html/adsense/adsense.php: line 8: syntax error near unexpected token `$destination'
/home/dcmg/public_html/adsense/adsense.php: line 8: `$postdata="destination=".urlencode($destination)."&username=".urlencode($username)."&password=".urlencode($password)."&null=Login";'

What should the command be in the cron job to trigger a .php file? It seems that this is my only problem as all the tests i've done have worked at the correct time. It just isn't starting the script correctly.

JohnKelly

11:23 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



Try this:
php /home/httpd/vhosts/domain.com/adsense.php >/dev/null 2>&1

Note that the actual path may be different, depending upon your server configuration.

You may also have to use the full path to the php, as in

/usr/bin/php /home/httpd/vhosts/domain.com/adsense.php >/dev/null 2>&1

(type "which php" to find where php is).

Hope this helps

dcmginc

11:44 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



Thanks JohnKelly... but those suggestions didn't work either. I did get something a little different for the output this time:

Content-type: text/html
X-Powered-By: PHP/4.3.7

<br />
<b>Fatal error</b>: Call to undefined function: curl_init() in <b>/home/dcmg/public_html/adsense/adsense.php</b> on line <b>10</b><br />

Any other ideas/suggestions?

JohnKelly

4:04 am on Feb 24, 2005 (gmt 0)

10+ Year Member



Do you have curl installed on your server?

newads

8:45 am on Feb 24, 2005 (gmt 0)

10+ Year Member



Kelly,

How to Install it on windows server...

Thanks In advance

JohnKelly

2:34 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Sorry, I don't know. I have a Unix server and curl was already installed.

dcmginc

4:46 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



John,

I just checked with the systemadmin and they say curl is on my account. I tried again and got the same error message:

Content-type: text/html
X-Powered-By: PHP/4.3.7

<br />
<b>Fatal error</b>: Call to undefined function: curl_init() in <b>/home/dcmg/public_html/adsense/adsense.php</b> on line <b>10</b><br />

bd4rr

2:49 am on Feb 25, 2005 (gmt 0)

10+ Year Member



dcmginc,

cURL is installed on server, but may NOT be compiled into PHP. See [ca3.php.net...] for more details.

Ken

kwongwo

3:41 am on Feb 25, 2005 (gmt 0)

10+ Year Member



Share my Windows ASP script:

File: TodayReport.asp

<!--#include file="inc/Clshttp.asp" -->
<%
destination="/adsense/reports-aggregate?product=afc&dateRange&dateRangeType=simple&dateRange&simpleDate=today"

'
Username="YourName@yourmail.com"
Password="*********************"

CsData="destination="&server.urlencode(destination)&"&username="&server.urlencode(username)&"&password="&server.urlencode(password)&"&null=Login"

Dim myThief,ResultStr

BeginStr="<td style=""text-align:right"" nowrap class="""" valign=""top"">"
Endstr=" </tr> "

set myThief=new clsThief

myThief.src="https://www.google.com/adsense/login.do"
myThief.PData=CsData
myThief.steal
myThief.cutX BeginStr ,Endstr

ResultStr="<tr><td>"&now&"</td>"&myThief.value '

' AddtoDB resultstr

Response.write ResultStr

'Response.redirect "list.asp"

set myThief=nothing 'free object

'====================================

%>

File: Clshttp.asp

aha, this class is too large to paste here,

pls send stickymail to me if you need ,and i will send it to you by email.

incrediBILL

3:51 am on Feb 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Anyone just implement this as a simple shell script?

Seems like overkill to use PHP when a simple crontab calling a script running CURL would be pretty trivial

Maybe I'll give it a shot later after The Apprentice....

GerBot

4:38 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



Firstly thanks to all the people who posted above me - I'm loving this Google income to phone thing!

I managed to get hwyking's php script working fine.

but not Tamen's

I really like the idea of getting these numbers asl well
$today = 'today';
$yesterday = 'yesterday';
$thismonth = 'thismonth';
$lastmonth = 'lastmonth';
$total = 'alltime';

did Tamen's script work for ayone else?

dcmginc

8:05 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



I tried, GerBot, but it didn't work for me either. I would much rather get that information sent to me. Though I'm still having problems with the cron job at the moment. Maybe I should just fix one problem at a time :)

tamen

8:20 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



Seems like its one of those rare scripts that works only at the writers place ;)

Is there any error-messages?

dcmginc

9:25 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



When I tried... I got a blank page with no error message. Just nothing.

hwyking

9:52 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



Here's what mine looks like in crontab.

55 * * * * /usr/local/bin/php -e /home/.rainer/punishr/adsense.php

Runs the script at the 55th minute of every hour.

dcmginc

10:41 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



That worked hwyking! Thanks so much... the -e made all the difference I guess :)

hwyking

11:04 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



sweet. glad you got it working. I'm guessing the -e means to execute?

dcmginc

11:48 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



I don't suppose you had any luck with tamen's version?
This 37 message thread spans 2 pages: 37