Having trouble authenticating Oath V1.6

May 19, 2014 at 3:21 PM

Great tool here, have a question about authenticating, Im trying to get access to the API to download the cover art images. Currently Im getting a 401 Unauthorized.

Here's my code, XXX,YYY AND ZZZ are my project, consumer code and secret key. Ive also received the authorization code from discogs.net.

Im currently receiving a "Object reference not set to an instance of an object" error on the AuthHeaders string variable.
DiscogsAuth auth = new DiscogsAuth("XXXX/1.0.3 +http://ctkme.com", "YYYY", "ZZZ");
string AuthHeaders = auth.AuthorizeApp("VERIFYCODE");
any help would be great!

May 19, 2014 at 4:01 PM
Edited May 19, 2014 at 4:03 PM
Do you have the DiscogsAuth auth = new DiscogsAuth("XXXX/1.0.3 +http://ctkme.com", "YYYY", "ZZZ"); outside a public for exemple
Public Class frmMain

Public Auth As DiscogsAuth

Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles frmMain.Load
        Auth = New DiscogsAuth("XXXX/1.0.3 +http://ctkme.com", "YYYY", "ZZZ")
        'Form initialization code
End Sub

End Class
And the rest of the code... That seems to me the problem
You have to declare outside the Function the Auth as Public so It's acessible throught the app and then on the form or the first step of the authentication you need to atribute the object the "Auth = New DiscogsAuth("XXXX/1.0.3 +http://ctkme.com", "YYYY", "ZZZ")
Jun 6, 2014 at 3:42 PM

Still having some issues authenticating to retrieve images.

Ive done the authentication procedure and received my AuthHeader code, how do I send it to properly authenticate to retrieve images and not receive the I heart discogs image using DiscogsNet OATH? I dont think Im understanding your provided documentation correctly, or Im missing something.

I have a search form, which posts the searchTerm to a controller like this:
function showListing(e) {
                url: "/AdminAjax/ProductSearchDiscogs",
                data: $('form').serialize(),
                method: "POST",
                success: function (result) {
controller code:
        public ActionResult ProductSearchDiscogs(Admin_DiscogsSearch discogSearch)
            var query = new DiscogsNet.Model.Search.SearchQuery()
                ReleaseTitle = discogSearch.SearchQuery,
                Type = SearchItemType.Release

             var auth = new DiscogsAuth("MYAPP/1.0.3 +http://MYDOMAIN.com", @ConfigurationManager.AppSettings["discogsKey"], @ConfigurationManager.AppSettings["discogsSecret"]);

            Discogs3 discogs = new Discogs3("MYAPP/1.0.3 +http://MYDOMAIN.com");

            var results = discogs.Search(query);
            var searchResults = new List<Admin_DiscogSearchResult>();

            foreach(var r in results.Results)
                var release = discogs.GetRelease(r.Id);
                var imagesList = new List<Admin_DiscogsImages>();

                if (release.Images != null)
                    foreach (var i in release.Images)
                        var n = new Admin_DiscogsImages()
                                Width = i.Width,
                                Height = i.Height,
                                URI = i.Uri


                var q = new Admin_DiscogSearchResult()
                        ReleaseId = string.Format("{0}", r.Id),
                        ReleaseName = r.Title,
                        Images = imagesList

                imagesList = null;

            return PartialView("~/_discogSearchResults.cshtml"), searchResults);
(MYAPP and MYDOMAIN are my application's specific keys -- MYAUTHKEY is my discogs API authkey using what I received using your provided documentation

DiscogsAuth auth = new DiscogsAuth("YourAppID/UserAgent","YourConsumerKey","YourConsumerSecret");

I am receiving all the data OK, and I am getting the image URL, but Im receiving the I Heart Discogs image. If i change the Uri
 var n = new Admin_DiscogsImages()
                                Width = i.Width,
                                Height = i.Height,
                                URI = i.Uri.Replace("api.discogs.com","s.pixogs.com")
i get a 404 error on the image when the partial view is returned.

Im definitely not properly authenticating using my AuthCode when querying, can I get your thoughts please on what Im doing wrong in authenticating the API call to the endpoint so that I dont see the I Heart Discogs image?

Jun 7, 2014 at 2:23 PM
Try to remove the authentication part of your code... Isn't needed because it does not work to retrieve images from discogs (discogs api bug)
  1. Try to get the image link replace the api.discogs.com with api.discogs.com and insert into your browser URL bar, if it loads everything is OK with the link
  2. Try adding the same link into an image tag <img src="image_link"> if it loads discogs isn't blocking your website and you may need to check your code (it seems OK to me) if it does not load discogs it's blocking your website from retrieving images
Jun 7, 2014 at 3:11 PM
You may try what I've said above with this link http://s.pixogs.com/image/A-90-252323-1283158116.jpeg
Jun 11, 2014 at 1:42 PM
ok -- so when i use the URI150 I am able to access things, which makes me believe there might be an issue with the speed of accessing the larger files. Their server may not be able to handle it?

When I run something like
using (WebClient client = new WebClient())
    client.DownloadFile(webUrl.Replace("api.discogs.com","s.pixogs.com"), tempImage);
where webURL is the passed URI from the data received, i get a 502 Gateway error.

Ive spoken with Discogs and they say there are no blocks on my account and should not be receiving a 502 for any knowledge they have, so its leading me to believe its the function of getting the image is too fast for the server to handle.

Any thoughts?
Jun 11, 2014 at 1:53 PM
Well I've bumped into the same problem on my project...
I don't know how to fix this because even when I'm on loop i've made an 10sec sleep and still got the 502 Gateway error... I've still not found the solution to this.
I'm gonna test a few tweeks to slow the function down... but I still think it's not gonna help

In my project I'm able to get the first 3/4 images and then it's only 502 errors

I I'm able to find a fix I will report it...
Jun 11, 2014 at 3:21 PM
Edited Jun 11, 2014 at 3:22 PM
Try storing the images on the disk so when you access some images if you have some on disk the other will probably load... IDK how much space do you have... I'm using something like this (vb.net desktop app)
Dim dirs() As String = Directory.GetDirectories(Application.StartupPath & "/bands/")
        discogs = New Discogs3("BandFollowerWD/1.0.3 +http://pcdev.pt/")
        Dim i As Integer = 0
        For Each bandID As String In dirs
            bandID = bandID.Replace(Application.StartupPath & "/bands/", "")
            Dim artist As DiscogsNet.Model.Artist = discogs.GetArtist(bandID)
            Dim itm As ListViewItem = New ListViewItem(artist.Name, i)

            Dim PicByte As Byte()

            If File.Exists(Application.StartupPath & "/bands/" & bandID & "/" & artist.Images(0).Uri150.Replace("http://api.discogs.com/image/", "")) Then
                PicByte = File.ReadAllBytes(Application.StartupPath & "/bands/" & bandID & "/" & artist.Images(0).Uri150.Replace("http://api.discogs.com/image/", ""))
                PicByte = discogs.GetImage(artist.Images(0).Uri150.Replace("api.discogs.com", "s.pixogs.com"))
                File.WriteAllBytes(Application.StartupPath & "/bands/" & bandID & "/" & artist.Images(0).Uri150.Replace("http://api.discogs.com/image/", ""), PicByte)
            End If

            Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream(PicByte)
            Me.Invoke(Sub() frmMain.ImageList1.Images.Add(Image.FromStream(ms)))

            itm.Tag = bandID
            Me.Invoke(Sub() frmMain.ListView1.Items.Add(itm))


            i = i + 1
Jun 11, 2014 at 3:43 PM
i was actually looking at doing that this morning -- did you have success with this?
Jun 11, 2014 at 5:30 PM
Not quite... It seemed to work because it loaded 2 or 3 more images then before... but does not seem to work... only increases the speed of loading (obvious)
Jun 12, 2014 at 2:55 AM
this seems to be working for me, by adding the User-Agent string to the client
 using (WebClient client = new WebClient())
                client.Headers["User-Agent"] ="APPNAME/1.0.3 +http://domain.com";
                client.DownloadFile(new Uri(webUrl.Replace("api.discogs.com", "s.pixogs.com")), tempImage);
Marked as answer by Hitmanpt on 6/12/2014 at 5:58 AM
Jun 12, 2014 at 12:58 PM
Indeed... It loaded all the images I'm gonna try implement it with the API