The problem:
According to Discogs:
Starting August 15th (2014), access to our search API endpoint (/database/search) will require OAuth authentication. We receive a large volume of anonymous search requests, and an overwhelming amount are failed requests (e.g., brute-force mp3 taggers), so we would like to be able to monitor these requests at the application level. This is part of an ongoing effort to improve API uptime and response times.
If your Discogs application is already sending authenticated requests to the search endpoint, you do not need to update any of your code. If you use the search endpoint but do not authenticate with OAuth, requests to the search endpoint will fail beginning August 15th, so please make the appropriate updates to your application!
All authenticated API calls will also be rate limited to 1 per second and a maximum of 1000 per day.
The solution:
* Add support for oauth authentication to all API calls.
* Limit request rates to 1 per second / 100 per day
==========
Original issue:
According to Discog:
Image requests will now require an application id. Image requests will also be limited to one per second and 1,000 per day, per application id.
So I am no longer able to get images imported because of this. I was looking through and trying to figure out where to add an API key, as I created my own Discog app to generate a key I could use, but I am not sure where to do that.
Thanks
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | Issue-2197875-by-Karlheinz-Ouath-required-for-discog.patch | 5.76 KB | Karlheinz |
Comments
Comment #1
Karlheinz commentedThis is really unfortunate, and not an easy fix at all.
To be clear, images don't require an API key (which I have). They require OAuth authentication. This is significantly more difficult to implement in the code.
It's entirely possible that the Discogs.com Provider sub-module may end up being dependent upon the OAuth module. This, in turn, depends upon PECL's OAuth extension, which does not come with PHP by default.
Also, OAuth is designed to be set up on a per-user basis. That means that the user gets redirected to a URL, where they log in to Discogs.com, and get some sort of authorization key that the "application" (here, Drupal) stores to use for all users' requests to the API. At least, that's how I understand it... I've never actually dealt with OAuth before.
So, yeah, this really sucks. I'm going to ask about it on the Discogs.com forums, and see what's going on.
Comment #2
jmac99999 commentedI think you are right, I am pretty sure they switched to the OAuth to limit the load on their servers, but I am sure it is a hassle to change your code. I looked through yours and their API docs and couldn't figure it out. I have been looking into using MusicBrainz as another source of data, and I got that working as a VM server (they supply an image) but haven't gotten too much further. For now, I use your thing then I use that module that lets you grab remote images easily (copy and paste the image itself or the URL). So it is ok for now.
Comment #3
Karlheinz commentedI think you are right, I am pretty sure they switched to the OAuth to limit the load on their servers, but I am sure it is a hassle to change your code.
That is exactly why they switched to OAuth. And the hassles won't just be limited to changing my code.
Here's how Discogs.com, a Drupal website, and the Drupal site's users interact:
As you can see, this is horrifically complicated, not just from my perspective, but from the perspectives of Drupal webmasters and site users. But that's how OAuth works, and there's no way around it.
From what I can tell, the Drupal OAuth module handles most of the latter steps (those after getting the Consumer Key and Consumer Secret). At least, those that happen without user interaction - site administers would still have to register as a Discogs.com developer, and site users would still have to log in to Discogs.com. I'm not sure what to do about the redirect URL, or if it's part of OAuth or specific to Discogs.com.
Comment #4
planet4sale commentedI have been following updates to this module for some time.
I see that In the last few months there have been a lot of API announcements, and the Changelog has been fairly active as well.
Assuming that things will soon stabilise, now might be a good time to get some Drupal 7 code working that imports Discogs data from current endpoints. I am thinking that with Drupal 8 coming along, there will be less enthusiasm to write 7 code in the future.
I would be interested to read any ideas on this!
Comment #5
tripper54 commentedI have a working discogs API integration running in a custom module I wrote for a group of radio stations.
The module grabs information from the station's automation system about what track is playing. There is a node type 'artist' which the drupal system checks the now playing info against. If no artist exists in the drupal app, it makes a call to discogs to retrieve bio and images and creates a new artist node.
I got oauth authentication working using the oauthsimple php library and some example code from the discogs forum.
See
https://github.com/jrconlin/oauthsimple/tree/master/php
http://www.discogs.com/forum/thread/53219ff8a86b6d57a82081f2#53219ff8a86...
The site adminstrator has to manually authorise the site to communicate with discogs. This is done once, thereafter the system is able to make calls to the API using the prior authentication.
Here's my authentication test function. There's some module specific stuff - variable_gets for API key and secret etc, but it might be a good starting point for integration into the discogs API module.
Note I originally wrote my custom module before this discogs module existed. If the discogs API module could be updated to support ouath, and offer some abstract methods, I would happy rewrite my module to use it, and put my efforts into this module!
Anyway, here's my oauth test page callback.
Comment #6
tripper54 commentedBy the way, you can see the results of my module in action at
http://www.2ch.com
:)
Comment #7
tripper54 commentedComment #8
tripper54 commentedComment #9
tripper54 commentedComment #10
strawberrybrick commentedModule no longer functions under Drupal 6, returns "Error importing from Discogs.com"
I am heavily invested in Discogs and Drupal 6, and would be willing to pay for either a fix or upgrade path. PM.
Comment #11
planet4sale commentedThanks for all recent responses. I think:
Version 7.x
The current module provides a multi-step form through which a user makes a request for “discography” data. Typically this is a search request to Discogs API. Maybe only a small amount of script changes are needed to make a successful search request with OAuth. At the same time there's a lot of potential for this module to do great stuff, with more changes, along the lines of the radio station module (maybe incorporated into a version 8 module?).
OAuth and OAuth libraries
OAuth has its share of supporters within the Drupal community, so I don't know if people using the Discogs module, will find other uses for OAuth but it's possible.
An OAuth library is used to simplify the process of authenticating. In the example on this page, with $oauthObject as the library object - you get:
There are various libraries compatible with versions of OAuth such as php-proauth library and php-proauth. The use of a library could break some scripts if there are conflicts between libraries. For reference Discogs used OAuth version 1.0a.
Provide a structured url example
To start with an example structured url would be helpful, maybe added to the help section of the module. The Discogs API provides an example search string without OAuth authentication.
Converted to PHP variables, the string can be divided into parts: a base URL and some query data). The query data can be further broken down into an array of key/value query pairs.
More housekeeping
The OAuth variables can be stored in the Drupal database. As an example do this:
Utilising PHP's CURL support
PHP's curl support is used in making request to Discogs API. It is used in the examples process of OAuth authentication on this page.
Thus:
the script does it's stuff to make a signed request, whether this for testing, finding variables to store, control a request process.
And, as a suggestion, we can start by using curl for sorting out problems with OAuth authentication .before moving onto changes to the current module (which doesn't use curl).
discogs_prov.module
The discogs_prov module has function discogs_prov_discog_search. It has a variable
used to build a structured URL.
Used at:
l.365 (new)
where http_build_query turns the parameter $query_data array into a string appended to a url. Actually looking at the Drupal API there is an equivalent function drupal_http_build_query
Now to encompass OAuth we need to add to query_data stuff / headers. And the data returned by the simpleoauth function sign gets added as key/value pairs.
Other variables
So we have a structured url for this search request, the way the multi-step form works need to consider there are other variables that should encompass OAuth authentication.
Therefore presumably need to have to build an array of query data, of key/value pairs each time (add OAuth to headers) for
l. 157
l.163 (new)
l.180 (new)
l.92 (new)
l.249 (new)
drupal_http_request()
If switching from implementation of curl then look at swapping over some curl_set_opt() variables to drupal_http_request options.
Parse returned result
If all goes well a $json_array should created which can be used to create content as before.
Comment #12
Presumo commentedPerhaps using the OAuth (+Connector) modules will help. I haven't quite got my head around OAuth for web sites as one user (or OAuth in general, for that matter).
Comment #13
sensifreak commentedHi,
Is there anyone that got the module up and running?
#push
Comment #14
strawberrybrick commented#push#push
Comment #15
Karlheinz commentedHey, it's Karl again. Sorry that I've been so quiet on this issue. I was in college full-time. I just graduated, and hopefully I can start fixing this.
There is actually some good news on this front. Because nobody liked working with OAuth for simple queries, Discogs.com created a new authentication service called "Discogs Auth." Essentially, you have to use HTTPS, and send the key/secret pair (or a token) either in the URL (easiest), or as part of the HTTP headers.
But, either way, this can be sent once the webmaster gets a Consumer Key and Consumer Secret - which is only done once. These can be stored as Drupal variables and sent automatically, so there wouldn't be any monkeying about with users having to be redirected and signing in on Discogs.com itself.
I've posted some questions about this on the Discogs forum (particularly if this will work with images), but if this type of authentication works, then it should be much easier to implement than OAuth would be.
Comment #16
strawberrybrick commentedPlease don't forget about version 6!
Comment #17
Karlheinz commentedGood news, everyone! Version 7 is working. Off to fix Version 6 right now.
BUT, note that you will still have to get a Consumer Key and Secret from Discogs.com. Yes, this means that you have to register as a developer. There's no way around this.
Patch against 7.x-1.x-dev is attached.
Comment #18
Karlheinz commentedComment #20
strawberrybrick commentedv6 please!
Comment #21
jmac99999 commentedThis is amazing news!!!! Thanks so much!!!!
Comment #22
jmac99999 commentedIs anyone else having a problem getting to the new discogs.com configuration page to enter the API keys/secrets? I get a blank page when I try to go to it.
admin/config/content/discogs-provider
I tried it on 2 different sites (test and prod) and get the same results. If I can't set this here, does anyone know where to set these manually? (databases table or is it in a config file, etc..).
Thanks!
Comment #23
Karlheinz commentedskurkee: It certainly works on my test machine. Did you try clearing the caches (admin/config/development/performance)? If I remember correctly, this will clear out the menu cache as well.
Comment #24
jmac99999 commentedYa, I cleared the cache but something is hung up. For now I just hard coded my keys into the module itself to get it working. I will worry about it later but for now, I am just thrilled to have it working again. Thanks again, great module!
Comment #25
Karlheinz commentedskurkee: It appears that the module won't let you enter the Key/Secret values. This is an issue that is different from OAuth authentication - it seems to be a problem with the Drupal module, not the Discogs API. It's a separate issue, so I created this: #2494843: Not able to enter OAuth keys
Having said that, I can't seem to reproduce this on my test machine. Once I can find the error, I will fix it.
Comment #26
Karlheinz commentedFYI, that latest issue is fixed (I hope). The fix is pushed to dev, and there's a patch on the issue: #2494843: Not able to enter OAuth keys.
It was a stupid mistake on my part - the admin file wasn't checked into the repo.