I've tried a lot of combinations of headers, but still get an empty result returned from curl. I know I need to send an auth token (which I do) and use SSL (which I am). This works in the browser. Am I missing something?
$agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2';
$path = "/tmp/timeline.csv";
$fp = fopen($path, 'w+');
$cookie_file_path = "../../../../private/tmp/cookies.txt";
$ch=curl_init();
$url = "https://artists.spotify.com/api/data/v1/artist/<ARTIST_URI>/timeline.csv";
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt( $ch, CURLOPT_CAINFO, realpath('../../../../Users/RMG/Desktop/cacert-2017-01-18.pem'));
curl_setopt($ch, CURLOPT_SSLVERSION,2);
curl_setopt($ch, CURLOPT_REFERER, 'https://artists.spotify.com/c/artist/<ARTIST_URI>/audience');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
//curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_HEADER, 1);
$auth_header = "Authorization: Bearer ". $accessToken;
curl_setopt($ch, CURLOPT_HTTPHEADER, array($auth_header,'Accept: */*; Content-type: application/csv','Content-Disposition: attachment; filename=timeline.csv','Pragma: no-cache','Expires: 0',));
curl_setopt($ch,CURLOPT_URL,$url);
$resp = curl_exec($ch);
curl_close($ch);
if (empty($resp)){
echo "Nothing returned from url.";
} else {
echo $resp;
}
This works fine in a browser using the same cookies. How do I emulate the browser further / what I am missing?