Skip to content

Instantly share code, notes, and snippets.

@Wol
Last active August 16, 2016 22:55
Show Gist options
  • Save Wol/0a0bf293760cf7accff4290280f9a9f3 to your computer and use it in GitHub Desktop.
Save Wol/0a0bf293760cf7accff4290280f9a9f3 to your computer and use it in GitHub Desktop.
Twitter Analytics PHP Downloader
<?php
$sTarget = "https://analytics.twitter.com/user/$username/tweets/export.json?start_time=$start_time&end_time=$end_time&lang=en";
$sTargetBundle = "https://analytics.twitter.com/user/$username/tweets/bundle?start_time=$start_time&end_time=$end_time&lang=en";
curl_setopt($ch, CURLOPT_URL, $sTarget);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$data_arr = ["status" => "Pending"];
$attempts = 0;
while($data_arr['status'] == "Pending" && $attempts < 5){
$data = curl_exec($ch);
$data_arr = json_decode($data, true);
sleep(2);
}
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_URL, $sTargetBundle);
$data = curl_exec($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment