PHP code om de statistieken van Google’s Adsense naar je email adres te laten sturen.
Speciaal voor alle Adsense junkies die regelmatig op de hoogte gehouden willen worden van de verdiensten tot nu toe. Pas onderstaande code naar eigen smaak aan en plak het in een PHP script. Maak een crontab aan die dit script op een bepaalde tijd uitvoert en voila: altijd op de hoogte.
#Wijzig onderstaande gegevens:
$username="XXXXXXXXXXX";
$password="XXXXXXXXXX";
$email="XXXXXXXXXX@XXXXX.NL";
#Nothing to change below this
header("Content-type: text/html");
$cookie="cookiefile";
$log="adsense.log.txt";
$destination="/adsense/reports-aggregate?product=afc&dateRange.";
$destination .= "dateRangeType=simple&dateRange.simpleDate=today";
$postdata="destination=".urlencode($destination)."&username=";
$postdata .= urlencode($username);
$postdata .="&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);
mail($email,"Verdiensten vandaag","$result);
Stem op dit artikel of voeg het toe aan:
Does this still work? I could not get it to work, nothing was being returned in $result
Thanks
Aaron