calliostro/discogs-bundle

Discogs API 客户端(适用于 Symfony 5 或 Symfony 6)的捆绑包

安装: 153

依赖关系: 0

建议者: 2

安全: 0

星标: 2

关注者: 1

分支: 8

开放问题: 1

类型:symfony-bundle

v3.0.1 2022-07-16 08:25 UTC

This package is auto-updated.

Last update: 2024-09-16 13:39:54 UTC


README

Build Status Version License

此捆绑包提供了将calliostro/php-discogs-api集成到 Symfony 5 或 6 的简单方式。您可以在其专属页面https://www.discogs.com/developers上找到更多关于此库的信息。

安装

请确保已全局安装 Composer,如 Composer 文档中的安装章节中所述。

使用 Symfony Flex 的应用程序

打开命令行控制台,进入您的项目目录并执行

$ composer require calliostro/discogs-bundle

不使用 Symfony Flex 的应用程序

步骤 1:下载捆绑包

打开命令行控制台,进入您的项目目录并执行以下命令以下载此捆绑包的最新稳定版本

$ composer require calliostro/discogs-bundle

步骤 2:启用捆绑包

然后,通过将其添加到项目 config/bundles.php 文件中注册的捆绑包列表中来启用捆绑包

// config/bundles.php

return [
    // ...
    Calliostro\DiscogsBundle\CalliostroDiscogsBundle::class => ['all' => true],
];

用法

此捆绑包提供了一个与 Discogs API 通信的单个服务,您可以通过使用 Discogs 类型提示来自动注入

// src/Controller/SomeController.php

use Discogs\DiscogsClient;
// ...

class SomeController
{
    public function index(DiscogsClient $discogs)
    {
        $artist = $discogs->getArtist([
            'id' => 8760,
        ]);

        echo $artist['name'];

        // ...
    }
}

配置

要配置,创建一个新的 config/packages/calliostro_discogs.yaml 文件。默认值如下

# config/packages/calliostro_discogs.yaml
calliostro_discogs:

  # Freely selectable and valid HTTP user agent identification (required)
  user_agent: 'CalliostroDiscogsBundle/2.0 +https://github.com/calliostro/discogs-bundle'

  # Your consumer key (recommended)
  consumer_key: ~

  # Your consumer secret (recommended)
  consumer_secret: ~

  throttle:
    # If activated, a new attempt is made later when the rate limit is reached
    enabled: true
    # Number of milliseconds to wait until the next attempt when the rate limit is reached
    microseconds: 1000000

  oauth:
    # If enabled, full OAuth 1.0a with access token/secret is used
    enabled: false
    # You can create a service implementing OAuthTokenProviderInterface (HWIOAuthBundle is supported by default)
    token_provider: calliostro_discogs.hwi_oauth_token_provider

客户端凭证

要访问受保护端点并获得更高的速率限制,您必须启用 OAuth。为此,您必须在 https://www.discogs.com/de/applications/edit 上注册至少 consumer_keyconsumer_secret

用户授权

要访问当前用户信息,您还需要一个用户令牌。Discogs 仅支持 OAuth 1.0a 进行用户授权。您应该使用第三方库来实现。此捆绑包为 hwi/HWIOAuthBundle 提供支持。如果使用 HWIOAuthBundle,则无需在配置文件中更改 token_provider

文档

有关 Discogs 客户端的文档,请参阅 calliostro/php-discogs-api

更多信息可在此Discogs API v2.0 文档中找到。

您可以在 calliostro/discogs-bundle-demo 中找到示例。

贡献

实现了缺失的功能?您可以提出请求。创建拉取请求是完成工作的更好方式。

另请参阅

有关将 Discogs 集成到 Symfony 2 的信息,请参阅基于此的 ricbra/RicbraDiscogsBundle