Giter Site home page Giter Site logo

ad_library_api's Introduction

Facebook_Ad_Library_API

๐Ÿšจ This library has been superceded internally, so we won't be maintaining it any further. ๐Ÿšจ

Thank you everyone who has contributed.

Scraping

Created by Roland Adorjani @RolandAdorjani

Python code package to scrape the Facebook Ad Library data

Who Targets Me have open-sourced this scraping package to make it easier for researchers to scrape the Facebook Ad Library, even if you have a limited knowledge of python.

See basic steps here or email [email protected] for any additional guidance:

  1. Download ad_library_api Zip

  2. Download Python/Anaconda distribution (version 3.7) https://www.anaconda.com/distribution/ See how to set up anaconda enviroment on your PC here: https://docs.anaconda.com/anaconda/user-guide/getting-started/

  3. Get Facebook Ad Library access token permissions (need to send I.d. and wait 24 hours for approval) https://www.facebook.com/ads/library/api/

  1. In ad_scraper.py go through four key changes:
  • A. Change 'countries = []' to include an ISO country code: https://www.nationsonline.org/oneworld/country_code_list.html

  • B. Change (args["access_token"] = 'insert') to insert Ad Library Access Token, available here: https://developers.facebook.com/tools/explorer/

  • C. Change Ad Library (args["search_terms"] = 'insert') to insert a search term or else do full search with '*'

  • D. Change the final line to the folder on your computer where you want the scraped csv to appear.

  • E. If you would like to change the range of the scrape, you can change the number of 'pages' the code scrapes here:

    i=0 next_page = r.get('paging', {}).get('next') print(next_page) for i in range(100):

    Or else to scrape every possible page since the ad library began (particularly if you just want to search a term) use this code instead:

    i=0 next_page = r.get('paging', {}).get('next') print(next_page) for i in range(100):

  1. In your terminal command line, locate the ad_library_api folder and run the ad_scaper.py file
  • "python3 ad_scraper.py"

If you receive the error "fbconn.py is not found" when you run the file A. In file ensure fbconn.py is in same folder as ad_scraper.py B. If persists, find out where facebook package is located with: pip show facebook-sdk C. Add the below code to the 'import' this file location into the 'import' section of the fbconn.py file ie.

import sys sys.path.insert(1, 'C:/Users/"insert PC user"/Anaconda3/envs/"insert your anaconda environment"/Lib/site-packages') import facebook"

Parsing

Created by Felix Szabo @fgszabo

Jupyter code package to clean the API csv (needed to lay out the demographic string into multiple columns based on gender and age breakdown)

In the terminal command line open Jupyter

'jupyter notebook'

Select WTM_Data_Gender_basic.ipynb and adapting the code

  • In[2]: Change the location/name of the source file
  • In [4]: Change the date range you wish to parse
  • In [15]: Change the name of the final file.

Run each line and final file will save to your desktop.

ad_library_api's People

Contributors

rachellavin27 avatar arvinnick avatar skinofstars avatar jjacobsen16 avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.