$username="you@email.com";
$password="MySuPeRpAsSwOrD";
$daterange = 20 ;
$cookie="./.cookiefile";
$daysbefore = mktime(0, 0, 0, date("m") , date("d") - $daterange, date("Y"));
list ($d_from,$m_from,$y_from) = split(':',date("j:n:Y", $daysbefore));
list ($d_to,$m_to,$y_to) = split(':',date("j:n:Y"));
$destination="/adsense/report/aggregate?"
."sortColumn=0"
."&reverseSort=false"
."&csv=true"
."&product=afc"
."&dateRange.simpleDate=today"
."&dateRange.dateRangeType=custom"
."&dateRange.customDate.start.day=$d_from"
."&dateRange.customDate.start.month=$m_from"
."&dateRange.customDate.start.year=$y_from"
."&dateRange.customDate.end.day=$d_to"
."&dateRange.customDate.end.month=$m_to"
."&dateRange.customDate.end.year=$y_to"
."&unitPref=page"
."&reportType=property"
."&searchField="
."&groupByPref=date";
$postdata="destination=".urlencode($destination)."&username=".urlencode($username)."&password=".urlencode($password)."&null=Login";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,"");
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);
$result=preg_split("/
/",$result);
array_pop($result);
array_pop($result);
array_shift($result);
$result = array_reverse($result);
header('Content-type: text/xml');
echo '';
echo "
";
?>
echo "$daterange days of Adsense"; ?>
An RSS feed of my Adsense earnings for the last echo $daterange ?> days
en
$firstday=1;
foreach ($result as $line) {
$item = array();
$line = str_replace("x00",'',$line);
$line = str_replace('"','',$line);
list($day, $pages, $clicks, $ctr, $eCPM, $income) = preg_split("/s/",$line);
$item['title']= "$$income on $day";
$item['guid'] = '' . md5($username.$day) . "";
$day = split('/',$day);
$day = mktime(0, 0, 0, $day[1] , $day[0], $day[2]);
if ($firstday == 1) {
$day = date("D, d M Y H:i:s +0000");
$firstday = 0;
} else {
$day = date("D, d M Y H:i:s +0000", $day);
}
$item['pubDate'] = "$day";
$item['category'] = "adsense";
$item['description'] = "$$income ($clicks clicks on $pages pages : CTR = $ctr - eCPM = $eCPM)";
$item['content'] = "< ![CDATA[
Pages printed | Clicks | CTR | eCPM | Earnings |
$pages | $clicks | $ctr | $eCPM | $income |
]]>";
print "
";
print $item['title'] ."
";
print $item['guid'] ."
";
print $item['pubDate'] ."
";
print $item['category'] ."
";
print $item['description'] ."
";
print $item['content'] ."
";
print "
";
}
?>
阅读(772) | 评论(0) | 转发(0) |