PHP code example of corncodecreators / discogs-api-client
1. Go to this page and download the library: Download corncodecreators/discogs-api-client 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/ */
corncodecreators / discogs-api-client example snippets
// create your client object
$discogsApiClient = new PersonalTokenClient();
// load the desired release-data from the Discogs API
$release = $discogsApiClient->requestDatabase()->getRelease(123);
// get the title of the release
$title = $release->getTitle();
// show all images of the release
foreach ($release->getImages() as $image) {
$url = $image->getResourceUrl();
echo "<img alt='{$title}' src='{$url}'>";
}
use CornCodeCreators\Discogs\Client\PersonalTokenClient;
$discogsApiClient = new PersonalTokenClient();
$release = $discogsApiClient->requestDatabase()->getRelease(1234);
// ...
use CornCodeCreators\Discogs\Client\PersonalTokenClient;
$userAgent = 'MyAgent';
$userToken = 'abcdefg';
$discogsApiClient = new PersonalTokenClient($userAgent, $userToken);
$release = $discogsApiClient->requestDatabase()->getRelease(1234);
// ...
use CornCodeCreators\Discogs\Client\OAuthClient;
$discogsApiClient = new OAuthClient();
$release = $discogsApiClient->requestDatabase()->getRelease(1234);
// ...
use CornCodeCreators\Discogs\Client\OAuthClient;
$userAgent = 'MyAgent';
$consumerKey = 'abcdefg';
$consumerSecret = '1234567';
$discogsApiClient = new OAuthClient($userAgent, $consumerKey, $consumerSecret);
$release = $discogsApiClient->requestDatabase()->getRelease(1234);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use CornCodeCreators\Discogs\Client\OAuthClient;
class OAuthController extends AbstractController
{
private $discogsApiClient;
public function __construct(
) {
$this->discogsApiClient = new OAuthClient();
}
#[Route('/oauth', name: 'app_oauth_step1')]
public function oauth(): RedirectResponse
{
$callbackUrl = $this->generateUrl('discogs_callback', [], UrlGeneratorInterface::ABSOLUTE_URL);
$tokens = $this->discogsApiClient->getRequestToken($callbackUrl);
return $this->redirect($this->discogsApiClient->getAuthorizeUrl());
}
#[Route('/callback', name: 'discogs_callback')]
public function callback(Request $request): RedirectResponse
{
$oauthVerifier = $request->query->get('oauth_verifier');
$tokens = $this->discogsApiClient->getAccessToken($oauthVerifier);
return $this->redirectToRoute('app_homepage');
}
#[Route('/home', name: 'app_homepage')]
public function home(): void
{
dump("Hello world! -> 'Dummy Homepage");
$release = $this->discogsApiClient->requestDatabase()->getRelease(249504);
dd($release);
}
}