最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Download Photos in Partner ( shared from other email ) using Python giving 400 error - Stack Overflow

programmeradmin4浏览0评论

Was trying to download Partner Photos.. getting

raise HttpError(resp, content, uri=self.uri)

googleapiclient.errors.HttpError: <HttpError 400 when requesting :search?alt=json returned "Invalid album ID.". Details: "Invalid album ID.">

def download_media_item(self, media_item, album_name):
    url = media_item['baseUrl'] + '=d'
    file_name = media_item['filename']
    media_id = media_item['id']
    media_version = media_item['mediaMetadata']['creationTime']
    album_dir = os.path.join('downloads', album_name)

    if not os.path.exists(album_dir):
        os.makedirs(album_dir)

    file_path = os.path.join(album_dir, file_name)

    # Check if file already exists in the MongoDB database
    result = self.mongo_collection.find_one({"id": media_id})
    if result and result['version'] == media_version:
        logging.info(f"File already exists and is up-to-date in MongoDB: {file_path}")
        return
    
    response = requests.get(url, stream=True)
    total_size = int(response.headers.get('content-length', 0))
    block_size = 1024
    t = tqdm(total=total_size, unit='B', unit_scale=True, desc=file_name)
    
    with open(file_path, 'wb') as f:
        for data in response.iter_content(block_size):
            t.update(len(data))
            f.write(data)
    t.close()
发布评论

评论列表(0)

  1. 暂无评论