Fetch Facebook's latest ad types and their requirements via facebook marketing api

Viewed 111

I have been looking through the facebook api documentation at https://developers.facebook.com/docs/marketing-api/, but have yet to find a solution for this. I simply want to get a list of facebook's latest ad types that are listed on this page: https://www.facebook.com/business/ads-guide as well as the specifications for each one. Is this possible via API?

Just to clarify, I don't want to access a specific facebook account's ads or campaigns. I just want to dynamically be able to fetch facebook's latest ad types and each ad types requirements via API without having to store this information within my database so as to avoid keeping up to date information manually.

I realize this isn't a specific coding problem, but any help in pointing me to the appropriate resources if this is possible would be much appreciated.

1 Answers

I think you don't need the API just the simple web-scraping tools that are out there - like requests and BeautifulSoup - there are lots of tutorials about how to web-scrape.

  1. Explore the website in its HTML - so you'd know what you are looking for

  2. Try to find the same HTML elements in your requests output -for your example that would looks something like this:

    import requests
    from bs4 import BeautifulSoup
    
    
    data = requests.get('https://www.facebook.com/business/ads-guide',verify=False)
    
    soup = BeautifulSoup(data.text, 'html.parser')
    # after looking at the page you can see that this is the class name that is used for the ad type tags
    relevant_fields = soup.find_all(class_="_3tms _80jr _8xn- _7oxw _34g8")[1:]
    # or optionally you can search for the heading3 types
    #relevant_fields = soup.find_all('h3')[1:]
    
    print([a.get_text() for a in relevant_fields])
    

enter image description here

Related