Методы получения изображений с примерами кода из Unsplash API

Чтобы создать список методов с примерами кода, связанными со случайным поисковым запросом в Unsplash, я предполагаю, что вы хотите получать изображения, используя их API. Вот пример использования языка программирования Python:

Метод 1: использование оболочки Unsplash API (PyUnsplash)

import pyunsplash
# Set up authentication credentials
pyunsplash.config.ACCESS_KEY = 'your_access_key'
pyunsplash.config.SECRET_KEY = 'your_secret_key'
# Search for photos using a random term
photos = pyunsplash.search.photos('random search term')
# Print the URLs of the first 10 photos
for photo in photos[:10]:
    print(photo.urls.regular)

Метод 2. Использование библиотеки запросов

import requests
# Set up authentication headers
headers = {
    'Authorization': 'Client-ID your_access_key',
}
# Search for photos using a random term
response = requests.get('https://api.unsplash.com/search/photos', headers=headers, params={'query': 'random search term'})
data = response.json()
# Print the URLs of the first 10 photos
for photo in data['results'][:10]:
    print(photo['urls']['regular'])

Метод 3. Использование Unsplash API (команда Curl)

curl --location --request GET 'https://api.unsplash.com/search/photos?query=random%20search%20term' \
--header 'Authorization: Client-ID your_access_key'