PHP AdSense帐户监视器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP AdSense帐户监视器相关的知识,希望对你有一定的参考价值。
php AdSense account monitor class, can retrieve data from your AdSense account (impressions, clicks, ctr, ecpm, earnings).This class can retrieve (for now) only “AdSense for Content†data, for different periods of time (see class methods for more details). You can implement this PHP class in your own applications.
Note: this code is absolete. Check new project at http://code.google.com/p/php-adsense-account-library/
//--------------------------------------------------------------------------------------------------------------------- //Source code for AdSense.php: //--------------------------------------------------------------------------------------------------------------------- /** * PHP class ment to collect AdSense account data * It can return various data for different periods of time * * @copyright Copyright © 2007 * @package AdSense */ class AdSense { /** * Stores curl connection handle * * @var resource */ var $curl = null; /** * Stores TMP folder path * This folder must be writeble * * @var string */ var $tmpPath = '/tmp'; /** * AdSense::AdSense() * AdSense class constructor */ function AdSense(){ curl_setopt($this->curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7"); } /** * AdSense::__destructor() * AdSense class destructor */ function __destructor(){ } /** * AdSense::connect() * Connects to AdSense account using supplied credentials * Returns true on unsuccessful connection, false otherwise * * @param string $username AdSense username * @param string $password AdSense password * @return boolean */ function connect($username, $password){ // phase 1 curl_setopt($this->curl, CURLOPT_URL, "https://www.google.com/accounts/ServiceLoginAuth?service=adsense&hl=en-US<mpl=login&ifr=true&passive=true&rm=hide&nui=3&alwf=true&continue=https%3A%2F%2Fwww.google.com%2Fadsense%2Fgaiaauth&followup=https%3A%2F%2Fwww.google.com%2Fadsense%2Fgaiaauth"); // phase 2 // phase 3 // did we login ? return true; } else { return false; }; } /** * AdSense::parse() * Parses AdSense page and gets all stats * Returns associative array with collected data * * @param string $content AdSense page content * @return array */ function parse($content){ preg_match_all('/<td nowrap valign="top" style="text-align:right" class="">(.*?)</td>/', $content, $matches); "impressions" => $matches[1][0], "clicks" => $matches[1][1], "ctr" => $matches[1][2], "ecpm" => $matches[1][3], "earnings" => $matches[1][4] ); } /** * AdSense::today() * Gets AdSense data for the period: today * Returns associative array with collected data * * @return array */ function today(){ curl_setopt($this->curl, CURLOPT_URL, "https://www.google.com/adsense/report/overview?timePeriod=today"); } /** * AdSense::yesterday() * Gets AdSense data for the period: yesterday * Returns associative array with collected data * * @return array */ function yesterday(){ curl_setopt($this->curl, CURLOPT_URL, "https://www.google.com/adsense/report/overview?timePeriod=yesterday"); } /** * AdSense::last7days() * Gets AdSense data for the period: last7days * Returns associative array with collected data * * @return array */ function last7days(){ curl_setopt($this->curl, CURLOPT_URL, "https://www.google.com/adsense/report/overview?timePeriod=last7days"); } /** * AdSense::lastmonth() * Gets AdSense data for the period: lastmonth * Returns associative array with collected data * * @return array */ function lastmonth(){ curl_setopt($this->curl, CURLOPT_URL, "https://www.google.com/adsense/report/overview?timePeriod=lastmonth"); } /** * AdSense::thismonth() * Gets AdSense data for the period: thismonth * Returns associative array with collected data * * @return array */ function thismonth(){ curl_setopt($this->curl, CURLOPT_URL, "https://www.google.com/adsense/report/overview?timePeriod=thismonth"); } /** * AdSense::sincelastpayment() * Gets AdSense data for the period: sincelastpayment * Returns associative array with collected data * * @return array */ function sincelastpayment(){ curl_setopt($this->curl, CURLOPT_URL, "https://www.google.com/adsense/report/overview?timePeriod=sincelastpayment"); } } //--------------------------------------------------------------------------------------------------------------------- //Source code for example.php //--------------------------------------------------------------------------------------------------------------------- include('AdSense.php'); $adsense = new AdSense(); if ($adsense->connect('username', 'password')) { $data = $adsense->sincelastpayment(); } else { };
以上是关于PHP AdSense帐户监视器的主要内容,如果未能解决你的问题,请参考以下文章
Wordpress 博客 + Google AdSense [关闭]