友声网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
开启左侧

把Google Adsense收入报表RSS输出

[复制链接]
vikingr 发表于 2010-4-22 11:37 | 显示全部楼层 |阅读模式
<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 />&lt; ?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=&quot;<a href="http://ys166.com/info/post/mailto:[email protected]">[email protected]</a>&quot;; <br />// your adsense username </p><p>$password=&quot;MySuPeRpAsSwOrD&quot;; <br />// your adsense password </p><p>$daterange = 20 ; <br />// range of days to aggregate in RSS reader </p><p>$cookie=&quot;./.cookiefile&quot;; <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(&quot;m&quot;) , date(&quot;d&quot;) - $daterange, date(&quot;Y&quot;)); <br />list ($d_from,$m_from,$y_from) = split(':',date(&quot;j:n:Y&quot;, $daysbefore)); <br />list ($d_to,$m_to,$y_to) = split(':',date(&quot;j:n:Y&quot;)); </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=&quot;/adsense/report/aggregate?&quot; <br />.&quot;sortColumn=0&quot; <br />.&quot;&amp;reverseSort=false&quot; <br />.&quot;&amp;csv=true&quot; <br />.&quot;&amp;product=afc&quot; <br />.&quot;&amp;dateRange.simpleDate=today&quot; <br />.&quot;&amp;dateRange.dateRangeType=custom&quot; <br />.&quot;&amp;dateRange.customDate.start.day=$d_from&quot; <br />.&quot;&amp;dateRange.customDate.start.month=$m_from&quot; <br />.&quot;&amp;dateRange.customDate.start.year=$y_from&quot; <br />.&quot;&amp;dateRange.customDate.end.day=$d_to&quot; <br />.&quot;&amp;dateRange.customDate.end.month=$m_to&quot; <br />.&quot;&amp;dateRange.customDate.end.year=$y_to&quot; <br />.&quot;&amp;unitPref=page&quot; <br />.&quot;&amp;reportType=property&quot; <br />.&quot;&amp;searchField=&quot; <br />.&quot;&amp;groupByPref=date&quot;; </p><p>$postdata=&quot;destination=&quot;.urlencode($destination).&quot;&amp;username=&quot;.urlencode($username).&quot;&amp;password=&quot;.urlencode($password).&quot;&amp;null=Login&quot;; </p><p>$ch = curl_init(); <br />curl_setopt ($ch, CURLOPT_URL,&quot;<a href="http://ys166.com/info/post/https://www.google.com/adsense/login.do">https://www.google.com/adsense/login.do</a>&quot;); <br />curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); <br />curl_setopt ($ch, CURLOPT_USERAGENT, &quot;Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)&quot;); <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(&quot;/\n/&quot;,$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 '&lsquo;; <br />echo &ldquo;\n&rdquo;; <br />?&gt; </p><p>xmlns:content=&quot;<a href="http://purl.org/rss/1.0/modules/content/">http://purl.org/rss/1.0/modules/content/</a>&quot; <br />xmlns:wfw=&quot;<a href="http://wellformedweb.org/CommentAPI/">http://wellformedweb.org/CommentAPI/</a>&quot; <br />xmlns:dc=&quot;<a href="http://purl.org/dc/elements/1.1/">http://purl.org/dc/elements/1.1/</a>&quot; <br />&gt; <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 &lt; ?php echo $daterange ?&gt; days <br />en <br />&lt; ?php </p><p>$firstday=1; </p><p>foreach ($result as $line) { <br />$item = array(); <br />$line = str_replace(&quot;\x00&quot;,'',$line); <br />$line = str_replace('&quot;','',$line); <br />list($day, $pages, $clicks, $ctr, $eCPM, $income) = preg_split(&quot;/\s/&quot;,$line); <br />$item['title']= &quot; <br />$item[&rsquo;guid&rsquo;] = &lsquo;&lsquo; . md5($username.$day) . &ldquo;&ldquo;; <br />$day = split(&rsquo;/',$day); <br />$day = mktime(0, 0, 0, $day[1] , $day[0], $day[2]); <br />if ($firstday == 1) { <br />$day = date(&rdquo;D, d M Y H:i:s +0000〃); <br />$firstday = 0; <br />} else { <br />$day = date(&rdquo;D, d M Y H:i:s +0000〃, $day); <br />} <br />$item[&rsquo;pubDate&rsquo;] = &ldquo; <br />$day&ldquo;; <br />$item[&rsquo;category&rsquo;] = &ldquo;&ldquo;; <br />$item[&rsquo;description&rsquo;] = &ldquo;\$$income ($clicks clicks on $pages pages : CTR = $ctr - eCPM = $eCPM)&ldquo;; <br />$item[&rsquo;content&rsquo;] = &ldquo;&lt; ![CDATA[ </p><p>]]&gt;&ldquo;; </p><p>print &ldquo;\n&rdquo;; <br />print $item[&rsquo;title&rsquo;] .&rdquo;\n&rdquo;; <br />print $item[&rsquo;guid&rsquo;] .&rdquo;\n&rdquo;; <br />print $item[&rsquo;pubDate&rsquo;] .&rdquo;\n&rdquo;; <br />print $item[&rsquo;category&rsquo;] .&rdquo;\n&rdquo;; <br />print $item[&rsquo;description&rsquo;] .&rdquo;\n&rdquo;; <br />print $item[&rsquo;content&rsquo;] .&rdquo;\n&rdquo;; <br />print &ldquo;\n&rdquo;; </p><p>} <br />?&gt;</p>

RSS|无图版|手机版|友声网 ( 鲁ICP备15020090号-1 )|网站地图 | | 点击这里给我发消息 |

GMT+8, 2024-12-28 00:42 , Processed in 0.015930 second(s), 7 queries , Gzip On, MemCache On.

Powered by Discuz! X

© ys166.com

快速回复 返回顶部 返回列表