DrRungø
DrRungø

Reputation: 9

Unable to change album settings with IMGUR API

I am trying to set up an imgur account for a school project where we have to create a website to store images in albums. I figured it would be a fun challenge to do, as I could make uploaded pictures and created albums persist between sessions. However, when I use the api to get all my albums ID's, I only get albums which are public. In addition to this, when I create an album, it always defaults to hidden, even though I have added "privacy","public"; to the body of the request. I can't change my account settings either, to make the default privacy public, as that simply doesn't work either. The first picture below is the response from my create album call, the second is the response when I fetch the album with the ID provided in the response from the first call. As you can see, I have set the privacy setting to public, but it somehow defaults to private.

Also, I have tried changing the settings of the album to public, after I have created it as private, this didn't work either.

This is my first time working with API's in javascript, so I hope I'm not missing something obvious.

Add album API call

Fetch album API call with ID from response from first call

Upvotes: 0

Views: 681

Answers (2)

Luka97
Luka97

Reputation: 1

I had the same problem. In my case it helped to throw ?privacy=public into the URL. Below is my code:

function privacy(albumId) {
    fetch(`https://api.imgur.com/3/album/${albumId}?privacy=public`, {
        method: 'PUT',
        headers: {
            Authorization: auth,
        },
        redirect: 'follow'
    })
        .then(response => response.text())
        .then(result => console.log(result))
        .catch(error => console.log('error', error));
}

Upvotes: 0

DrRungø
DrRungø

Reputation: 9

Apparently when you create an album, and add an existing image from imgur in the process, you can fetch the album id with the API call that fetches the ID's of all albums associated with your account. This doesn't make the album public, that bug persists, but this is a workaround.

To be clear!

Add an existing image from imgur to your album when you create it, then you can fetch the ID's afterwards.

Upvotes: 0

Related Questions