Last active
August 16, 2016 22:55
-
-
Save Wol/0a0bf293760cf7accff4290280f9a9f3 to your computer and use it in GitHub Desktop.
Twitter Analytics PHP Downloader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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