PHP code example of tnd / api-discogs

1. Go to this page and download the library: Download tnd/api-discogs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tnd / api-discogs example snippets



$client = Discogs\ClientFactory::factory([]);


$client = Discogs\ClientFactory::factory([
    'defaults' => [
        'headers' => ['User-Agent' => 'your-app-name/0.1 +https://www.awesomesite.com'],
    ]
]);



$client = Discogs\ClientFactory::factory();
$client->getHttpClient()->getEmitter()->attach(new Discogs\Subscriber\ThrottleSubscriber());


$client = ClientFactory::factory([
    'defaults' => [
        'query' => [
            'key' => 'my-key',
            'secret' => 'my-secret',
        ],
    ]
]);



$client = Discogs\ClientFactory::factory([]);
$oauth = new GuzzleHttp\Subscriber\Oauth\Oauth1([
    'consumer_key'    => $consumerKey, // from Discogs developer page
    'consumer_secret' => $consumerSecret, // from Discogs developer page
    'token'           => $token['oauth_token'], // get this using a OAuth library
    'token_secret'    => $token['oauth_token_secret'] // get this using a OAuth library
]);
$client->getHttpClient()->getEmitter()->attach($oauth);

$response = $client->search([
    'q' => 'searchstring'
]);



$client = Discogs\ClientFactory::factory([]);
$history = new GuzzleHttp\Subscriber\History();
$client->getHttpClient()->getEmitter()->attach($history);

$response = $client->search([
    'q' => 'searchstring'
]);

foreach ($history as $row) {
    print (string) $row['request'];
    print (string) $row['response'];
}




$response = $client->search([
    'q' => 'Meagashira'
]);
// Loop through results
foreach ($response['results'] as $result) {
    var_dump($result['title']);
}
// Pagination data
var_dump($response['pagination']);

// Dump all data
var_dump($response->toArray());




$label = $service->getLabel([
    'id' => 1
]);




$artist = $service->getArtist([
    'id' => 1
]);




$release = $service->getRelease([
    'id' => 1
]);

echo $release['title']."\n";



$master  = $service->getMaster([
    'id' => 1
]);

echo $master['title']."\n";



$folders = $service->getCollectionFolders([
    'username' => 'example'
]);



$folder = $service->getCollectionFolder([
    'username' => 'example',
    'folder_id' => 1
]);



$items = $service->getCollectionItemsByFolder([
    'username' => 'example',
    'folder_id' => 3
]);

php

$release = $client->getRelease([
    'id' => 1
]);
foreach ($release['images'] as $image) {
    $response = $client->getHttpClient()->get($image['uri']);
    // response code
    echo $response->getStatusCode();
    // image blob itself
    echo $client->getHttpClient()->get($image['uri'])->getBody()->getContents();
}