简体   繁体   English

如何使用Zend_Oauth连接到Discogs Api?

[英]How to connect to Discogs Api using Zend_Oauth?

I'm attempting to connect to discogs.com api with Zend_Oauth as part of a custom Magento module. 我正在尝试使用Zend_Oauth作为自定义Magento模块的一部分连接到discogs.com api。

Discogs API details are here: Discogs API详细信息在这里:

accessing 进入

oauth 认证

I've followed details for using Zend Oauth here: introduction 我在这里关注了使用Zend Oauth的详细信息: 简介

Suggested code is as follows... 建议的代码如下...

(I've set up a test account on Discogs so the Key and Secret here are correct and live and can be tested.) (我已经在Discogs上设置了一个测试帐户,因此此处的“密钥”和“秘密”是正确的,实时的并且可以进行测试。)

$config = array(
    'callbackUrl' => 'http://www.example-discogs-app.co.uk',
    'siteUrl' => 'http://api.discogs.com/oauth',
    'consumerKey' => 'qvJGTkWsbVMGZGYCHCrQ',
    'consumerSecret' => 'iBMnIrhFzoHjqaiVbkhhrmipzcaBwBCc'
    );
$consumer = new Zend_Oauth_Consumer($config);

// fetch a request token
$token = $consumer->getRequestToken();

// persist the token to storage
$_SESSION['DISCOGS_REQUEST_TOKEN'] = serialize($token);

// redirect the user
$consumer->redirect();

I get a request token and get redirected to: api.discogs.com/oauth/authorize?oauth_token=xyzrequesttoken 我收到请求令牌并重定向到:api.discogs.com/oauth/authorize?oauth_token=xyzrequesttoken

With this displayed: 显示如下:

"{"message": "The requested resource was not found."}" “ {” message“:”找不到所请求的资源。“}”

NB: When I run the same code against Twitter API Oauth with the relevant account key details it works and redirects to twitter for access confirmation as it should. 注意:当我使用相关的帐户密钥详细信息对Twitter API Oauth运行相同的代码时,它将起作用,并重定向至Twitter,以进行访问确认。

I've tried various $config settings with no luck, eg requestScheme, requestMethod,. 我尝试了各种$ config设置,但是没有运气,例如requestScheme,requestMethod等。

I figured it could be something to do with required headers so I've also tried replacing $consumer->redirect(); 我认为这可能与所需的标头有关,因此我也尝试替换$ consumer-> redirect();。 with the following... ($token being extracted from the $token response above) 与以下...(从上面的$ token响应中提取$ token)

$client = new Zend_Http_Client();
$client->setHeaders('Content-Type: application/json');
$client->setHeaders('User-Agent: +Xyz');
$client->setUri('http://api.discogs.com/oauth/authorize?oauth_token='.$token);
$client->setMethod(Zend_Http_Client::POST);
$response = $client->request();

I get the same response: 我得到相同的响应:

"{"message": "The requested resource was not found."}" “ {” message“:”找不到所请求的资源。“}”

Any help would be much appreciated. 任何帮助将非常感激。

The kind people at discogs pointed out that the authorize url should be www not api so the correct config that works looks like this: discogs的友善人士指出,授权url应该是www而不是api,因此有效的正确配置如下所示:

    $config = array(
        'callbackUrl' => http://www.example-discogs-app.co.uk,
        'consumerKey' => 'tJOGhRhfsCQKnGCaOZin',
        'consumerSecret' => 'dxyrhywgvMgVqrZsmncCrQyAXnRHwZVq',
        'requestTokenUrl' => 'http://api.discogs.com/oauth/request_token',
        'authorizeUrl' => 'http://www.discogs.com/oauth/authorize',
        'accessTokenUrl' => 'http://api.discogs.com/oauth/access_token',
    );   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM