如何使用Python Unsplash API获取随机图像的URL而不是随机照片ID?

2024-04-28 20:33:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是来自github的python和python unsplash api(下面的链接)。我正试图找到一种方法通过api获取随机照片的URL,但却遇到了照片ID。我不知道如何找到相应的URL,以与使用命令时返回的照片ID相匹配(如下面的代码所示)

没有出现任何错误消息

Python-Unsplash GitHub API Documentation

Normal Unsplash API Documentation

from unsplash.api import Api
from unsplash.auth import Auth

client_id = "#this would normally be my access key"         #authenticating
client_secret = ""                                          #my profile
redirect_uri = ""                                           
code = ""

auth = Auth(client_id, client_secret, redirect_uri, code=code)
api = Api(auth)

img= api.photo.random(orientation = 'landscape' )   #gets id of random photo

print(img)


print(api.photo.get('wzfOt1uwzxc')) #I was hoping this would return URL but doesn't

Tags: fromimportclientauthapiidurldocumentation