Search code examples
pythonfacebook

How can I download facebook video using python


I'm making a facebook messenger chat bot using fbchat. Now I want to add facebook video download feature. I want to input the video url and get back the src download url as return.

I tired to add some thirdparty API's but non of them works.


Solution

  • import requests
    
    def download_facebook_video(url, save_path):
    response = requests.get(url, stream=True)
    
    if response.status_code == 200:
        with open(save_path, 'wb') as f:
            for chunk in response.iter_content(chunk_size=1024):
                f.write(chunk)
        print("Video downloaded successfully!")
    else:
        print("Failed to download video.")
    
    # Example usage
    video_url = '<YOUR_FACEBOOK_VIDEO_URL>'
    save_file_path = '<PATH_TO_SAVE_VIDEO>'
    download_facebook_video(video_url, save_file_path)
    

    Make sure you have necessary permission from Facebook to download videos