Skip to content

Instantly share code, notes, and snippets.

@jklein
Created November 1, 2013 02:52
Show Gist options
  • Save jklein/7260380 to your computer and use it in GitHub Desktop.
Save jklein/7260380 to your computer and use it in GitHub Desktop.
<?php
// Date format: YYYY/MM/DD
function getVimeoData($start_date, $end_date) {
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://vimeo.com/stats?action=totals&start_date=" . urlencode($start_date) . "&end_date=" . urlencode($end_date) . "&update_chart=false");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$cookie_val = "vimeo=<session_id_goes_here>;";
curl_setopt($ch, CURLOPT_COOKIE, $cookie_val);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Request:JSON", "X-Requested-With:XMLHttpRequest"));
// grab URL and pass it to the browser
$content = curl_exec($ch);
curl_close($ch);
$page_content = json_decode($content, true);
$stats = $page_content['stats'];
foreach ($stats as $stat) {
foreach ($stat as $name => $value) {
echo $name . ': ' . $value . "\n";
// Log somewhere
}
}
}
for ($i=1; $i <= 12; $i++) {
$start_date = date("Y/m/01", strtotime("2012-$i-01"));
$end_date = date("Y/m/t", strtotime("2012-$i-01"));
getVimeoData($start_date, $end_date);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment