This article mainly introduces the usage of CompeteAPI in the php website access statistics class. The example analyzes php's skills in using curl to obtain Compete website information, which has some reference value, for more information about how to use the Compete API in php to obtain website access statistics, see the following example. Share it with you for your reference. The details are as follows:
Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.
This example describes the usage of the Compete API used by php to obtain website access statistics. Share it with you for your reference. The details are as follows:Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.
___FCKpd___0
I hope this article will help you with php programming.
UrlKeys = array (': domain', ': metric', ': key'); privateThis example describes the usage of the Compete API used by php to obtain website access statistics. Share it with you for your reference. The details are as follows:
Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.
___FCKpd___0
I hope this article will help you with php programming.
ApiKey;/*** For url cleaning. */privateThis example describes the usage of the Compete API used by php to obtain website access statistics. Share it with you for your reference. The details are as follows:
Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.
___FCKpd___0
I hope this article will help you with php programming.
ToSearch = array ('http: // ', 'www.'); privateThis example describes the usage of the Compete API used by php to obtain website access statistics. Share it with you for your reference. The details are as follows:
Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.
___FCKpd___0
I hope this article will help you with php programming.
ToReplace = array ('','');/*** List of available metrics. */privateThis example describes the usage of the Compete API used by php to obtain website access statistics. Share it with you for your reference. The details are as follows:
Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.
___FCKpd___0
I hope this article will help you with php programming.
AvailableMetrics = array (// Description Auth type 'uv', // Unique Visitors Basic 'vis ', // Visits Basic 'rank', // rank Basic 'pv ', // Page Views All-Access 'avstay', // Average Stay All-Access 'vps', // Visits/Person All-Access 'vppu ', // Pages/Visit All-Access 'Att ', // Attention All-Access 'reachd', // Daily Reach All-Access 'attd ', // Daily Attention All-Access 'Gen', // Gender All-Access 'age', // age All-Access 'INC', // Income All-Access ); /*** List of available methods for _ call () implementation. */privateThis example describes the usage of the Compete API used by php to obtain website access statistics. Share it with you for your reference. The details are as follows:
Here, we use php to obtain the website access statistics class Compete API. Compete is a website dedicated to collecting website information.
___FCKpd___0
I hope this article will help you with php programming.
Metrics = array ('uniquevisitors '=> 'u', 'visits' => 'vis ', 'rank' => 'rank ', 'pageview' => 'PV ', 'averagestay' => 'avstay', 'visitsperson '=> 'vps', 'pagesvisit' => 'vppu', 'attention' => 'Att ', 'dailyad' => 'reachd', 'dailyattention '=> 'attd', 'gender' => 'Gen', 'age' => 'age ', 'Welcome '=> 'INC');/*** Create access to Compete API. * @ param string $ apiKey user's api key. */public functi On _ construct ($ apiKey) {$ this-> _ apiKey = $ apiKey;}/*** Implement specific methods. */public function _ call ($ name, $ args) {if (array_key_exists ($ name, $ this-> _ metrics) & isset ($ args [0]) return $ this-> get ($ args [0], $ this-> _ metrics [$ name]); throw new CompeteException ($ name. 'method does not exist. ');}/*** Get data from Compete. * @ param string $ site some domain. * @ param string $ metric Metric to get. * @ return stdClass Compete data. * @ throws CompeteException */public function get ($ site, $ metric) {if (! In_array ($ metric, $ this-> _ availableMetrics) throw new CompeteException ($ metric. '-wrong metric. '); $ values = array ($ this-> _ prepareUrl ($ site), $ metric, $ this-> _ apiKey ); // Prepare call url $ url = str_replace ($ this-> _ urlKeys, $ values, self: API_BASE_URL); // Retrieve data using http get method. $ data = json_decode ($ this-> _ get ($ url); // Because of unsuccessful responses contain "status_message". If (! Isset ($ data-> status_message) return $ data; throw new CompeteException ('status :'. $ data-> status. '. '. $ data-> status_message);}/*** Cut unnecessary parts of url. * @ param string $ url some url. * @ return string trimmed url. */private function _ prepareUrl ($ url) {return str_replace ($ this-> _ toSearch, $ this-> _ toReplace, $ url );} /*** Execute http get method. * @ param string $ url request url. * @ return string response. */private function _ get ($ url) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_USERAGENT, self :: USER_AGENT); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true); return curl_exec ($ ch );}}
I hope this article will help you with php programming.