【发布时间】:2015-03-12 03:20:29
【问题描述】:
在 Discogs API (https://github.com/ricbra/php-discogs-api) 的 PHP 5.4 实现中,有一个示例如何获取 $response = $client->search(['q' => 'Meagashira']);使用 oauth1。示例说明:
$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
]);
consumer_key 和 consumet_secret 在 discogs 应用设置中给出。如何获取 token 和 token_secret?我尝试让这个示例代码在命令行中工作,但我主要得到一堆异常:
PHP 致命错误:未捕获的异常 带有消息“客户端错误”的“GuzzleHttp\Exception\ClientException” 回复 [网址] http://api.discogs.com/database/search?q=Metallica [状态码] 401 [原因短语] Unauthorized' in /var/www/darkplanet/vendors/composer/guzzlehttp/guzzle/src/Exception/RequestException.php:
【问题讨论】:
-
通常是您的 OAuth 提供商提供的令牌和密码。您为 SSO 使用的是谁?例如,如果你可以使用 GitHub 登录,那么 GitHub 的管理面板就会有这些数据。
-
看看Discogs developer documentation,它解释了如何以及在哪里获取令牌和令牌秘密。
标签: php oauth guzzle discogs-api