-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurl.php
More file actions
29 lines (22 loc) · 974 Bytes
/
curl.php
File metadata and controls
29 lines (22 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
$client_id = '4e5ec5f49f504198805e6bd7285f5253';
$client_secret = 'e0fec4ef01344931835066c3344654c1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://accounts.spotify.com/api/token' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
$head = array('Authorization: Basic '.base64_encode($client_id.':'.$client_secret));
curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
$token = json_decode(curl_exec($ch), true);
curl_close($ch);
$query = urlencode($_GET["q"]);
$url = 'https://api.spotify.com/v1/search?type=track&q='.$query;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$token['access_token']));
$res=curl_exec($ch);
curl_close($ch);
echo $res;
?>