Quantcast
Viewing all articles
Browse latest Browse all 14069

Google Drive uc?id= no longer works

I am trying to write code to get the direct urls of images in a public Google Drive folder and embed them. Until a few minutes ago everything has been working and using the uc? trick gives the raw image so I can embed it. However now it is sending a download, even when I use &export=view.

Here is my code:

key = "supersecretgooglecloudconsolekey"import reimport requestsdef get_raw_image_links(folder_link):    # Extract folder id    folder_id = re.findall(r"/folders/([^\s/]+)", folder_link)[0]    # Google cloud console request to get links    api_url = f"https://www.googleapis.com/drive/v3/files?q='{folder_id}'+in+parents+and+mimeType+contains+'image/'&key={key}"    response = requests.get(api_url).json()    raw_image_links = []    # Iterate over the files and retrieve raw image links    for file in response['files']:        raw_link = f"https://drive.google.com/uc?id={file['id']}"        print(raw_link)        raw_image_links.append(f'<a href="{raw_link}"> <img src="{raw_link}" /> </a>')    return ''.join(raw_image_links)folder_link = "https://drive.google.com/drive/u/0/folders/**********"image_links = get_raw_image_links(folder_link)

For example, this works: https://drive.google.com/uc?id=15bwLlBuPc4O8LXwxjsBJe_ctyPl8Tll2

But this doesn't for some reason and instead sends a download: https://drive.google.com/uc?id=1Gz4YrH2tefSVxKRvv6gnqnY3tk0Obm0T

How do I fix this? Also, it would be helpful if anyone knows how to scrape the raw image link from the viewing page of the image itself https://drive.google.com/file/d/15bwLlBuPc4O8LXwxjsBJe_ctyPl8Tll2/view

Thank you!


Viewing all articles
Browse latest Browse all 14069

Trending Articles