<p>这是一个简单的脚本,通过Google Adsense API 接口为 Google Adsense 的收入报表创建 RSS 输出,你可以用你喜欢的RSS阅读工具来查看Adsense 的收入情况。 </p><p>设置和使用: <br />1. 复制下面的代码保存为一个任何名字的.php文件。 <br />2. 修改代码前面几行中你的 Google adsense 用户名,密码等信息。 <br />3. 上传你修改后的php文件到你的服务器的一个秘密的地方(防止别人查看你的收入情况),这样就可用你的RSS阅读工具来查看 Google Adsense 的收入了。 </p><p><br />< ?php <br />/* <br />Hack Name: Adsense to RSS <br />Version: 1.0 <br />Hack URI: <a href="http://frenchfragfactory.net/ozh">http://frenchfragfactory.net/ozh</a> ... rnings-in-rss-feed/ <br />Description: Follow your Adsense earnings with an RSS reader <br />Author: Ozh <br />Author URI: <a href="http://planetOzh.com">http://planetOzh.com</a> <br />*/ </p><p>/************ SCRIPT CONFIGURATION ***********/ <br />/*********************************************/ </p><p>$username="<a href="http://ys166.com/info/post/mailto:[email protected]">[email protected]</a>"; <br />// your adsense username </p><p>$password="MySuPeRpAsSwOrD"; <br />// your adsense password </p><p>$daterange = 20 ; <br />// range of days to aggregate in RSS reader </p><p>$cookie="./.cookiefile"; <br />// a temp file name - you mostly don't care about this <br />// This will create a hidden file in the current directory. If it seems to fail, <br />// replace with a full physical path (i.e. /home/you/temp/cookiefile) </p><p>/************ DO NOT MODIFY BELOW ************/ <br />/*********************************************/ </p><p>$daysbefore = mktime(0, 0, 0, date("m") , date("d") - $daterange, date("Y")); <br />list ($d_from,$m_from,$y_from) = split(':',date("j:n:Y", $daysbefore)); <br />list ($d_to,$m_to,$y_to) = split(':',date("j:n:Y")); </p><p>/* Following lines are based on a script found on WMW forums */ <br />/* <a href="http://www.webmasterworld.com/forum89/5349.htm">http://www.webmasterworld.com/forum89/5349.htm</a> */ </p><p>$destination="/adsense/report/aggregate?" <br />."sortColumn=0" <br />."&reverseSort=false" <br />."&csv=true" <br />."&product=afc" <br />."&dateRange.simpleDate=today" <br />."&dateRange.dateRangeType=custom" <br />."&dateRange.customDate.start.day=$d_from" <br />."&dateRange.customDate.start.month=$m_from" <br />."&dateRange.customDate.start.year=$y_from" <br />."&dateRange.customDate.end.day=$d_to" <br />."&dateRange.customDate.end.month=$m_to" <br />."&dateRange.customDate.end.year=$y_to" <br />."&unitPref=page" <br />."&reportType=property" <br />."&searchField=" <br />."&groupByPref=date"; </p><p>$postdata="destination=".urlencode($destination)."&username=".urlencode($username)."&password=".urlencode($password)."&null=Login"; </p><p>$ch = curl_init(); <br />curl_setopt ($ch, CURLOPT_URL,"<a href="http://ys166.com/info/post/https://www.google.com/adsense/login.do">https://www.google.com/adsense/login.do</a>"); <br />curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); <br />curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); <br />curl_setopt ($ch, CURLOPT_TIMEOUT, 20); <br />curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,1); <br />curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); <br />curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); <br />curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie); <br />curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); <br />curl_setopt ($ch, CURLOPT_POST, 1); <br />$result = curl_exec ($ch); <br />curl_close($ch); </p><p>$result=preg_split("/\n/",$result); <br />array_pop($result); <br />array_pop($result); <br />array_shift($result); <br />$result = array_reverse($result); </p><p>header('Content-type: text/xml'); <br />echo '‘; <br />echo “\n”; <br />?> </p><p>xmlns:content="<a href="http://purl.org/rss/1.0/modules/content/">http://purl.org/rss/1.0/modules/content/</a>" <br />xmlns:wfw="<a href="http://wellformedweb.org/CommentAPI/">http://wellformedweb.org/CommentAPI/</a>" <br />xmlns:dc="<a href="http://purl.org/dc/elements/1.1/">http://purl.org/dc/elements/1.1/</a>" <br />> <br /><a href="http://ys166.com/info/post/https://www.google.com/adsense/">https://www.google.com/adsense/</a> An RSS feed of my Adsense earnings for the last < ?php echo $daterange ?> days <br />en <br />< ?php </p><p>$firstday=1; </p><p>foreach ($result as $line) { <br />$item = array(); <br />$line = str_replace("\x00",'',$line); <br />$line = str_replace('"','',$line); <br />list($day, $pages, $clicks, $ctr, $eCPM, $income) = preg_split("/\s/",$line); <br />$item['title']= " <br />$item[’guid’] = ‘‘ . md5($username.$day) . ““; <br />$day = split(’/',$day); <br />$day = mktime(0, 0, 0, $day[1] , $day[0], $day[2]); <br />if ($firstday == 1) { <br />$day = date(”D, d M Y H:i:s +0000〃); <br />$firstday = 0; <br />} else { <br />$day = date(”D, d M Y H:i:s +0000〃, $day); <br />} <br />$item[’pubDate’] = “ <br />$day“; <br />$item[’category’] = ““; <br />$item[’description’] = “\$$income ($clicks clicks on $pages pages : CTR = $ctr - eCPM = $eCPM)“; <br />$item[’content’] = “< ![CDATA[ </p><p>]]>“; </p><p>print “\n”; <br />print $item[’title’] .”\n”; <br />print $item[’guid’] .”\n”; <br />print $item[’pubDate’] .”\n”; <br />print $item[’category’] .”\n”; <br />print $item[’description’] .”\n”; <br />print $item[’content’] .”\n”; <br />print “\n”; </p><p>} <br />?></p> |