'Unsplash API OAuth error: The access token is invalid

I am using the /search/photos endpoint of Unsplash's API to retrieve pictures given a specific query.

Here is the get request:

unsplash_request_url = "https://api.unsplash.com/search/photos?query=#{query}&content_filter=high&client_id=#{ENV['UNSPLASH_ACCESS_KEY']}"

html = URI.open(unsplash_request_url)
return JSON.parse(Nokogiri::HTML(html.read))

As stated in the documentation, I pass the Access token I got with the client_id parameter.

However, I get the following error:

OAuth error: The access token is invalid

I tried to remove the client_id parameter and add the access token in the Authorization header, but I get the same error.

Any idea how to solve this issue? Thanks.



Solution 1:[1]

Make sure you are providing the access key and not the secret key to the endpoint.

I tested your code with an access key and it works fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dalemonaco