· 7 years ago · Apr 12, 2018, 09:18 PM
1$consumer_key = getenv('DISCOGS_CONSUMER_KEY');
2$secret_key = getenv('DISCOGS_CONSUMER_SECRET');
3$options = array('http' => array('user_agent' => 'Example/alpha +https://example.com'));
4$context = stream_context_create($options);
5$results = file_get_contents('https://api.discogs.com/database/search?q='.$term.'&key='.$consumer_key.'&secret='.$secret_key.'&per_page=10', false, $context);
6
7$url = 'https://api.discogs.com/database/search?q='.$term.'&key='.$consumer_key.'&secret='.$secret_key.'&per_page=10';
8$ch = curl_init();
9curl_setopt($ch, CURLOPT_USERAGENT, 'Example/alpha +https://example.com');
10curl_setopt($ch, CURLOPT_URL, $url);
11curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
12$output = curl_exec($ch);
13curl_close ($ch);
14die($output); // 400 "Bad Request"
15
16$url = 'https://api.discogs.com/database/search?q='.$term.'&key='.$consumer_key.'&secret='.$secret_key.'&per_page=10';
17$ch = curl_init();
18curl_setopt($ch, CURLOPT_USERAGENT, 'Example/alpha +https://example.com');
19curl_setopt($ch, CURLOPT_ENCODING, 'Example/alpha +https://example.com');
20curl_setopt($ch, CURLOPT_URL, $url);
21curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
22$output = curl_exec($ch);
23curl_close ($ch);
24
25// Then do whatever you wish with $output