This script was used to extract data from Facebook's Marketing API.
Frankly, It's a mess. It was one of the first scripts I've ever written and It's not doing a lot of things right.
I'm going to keep it here because I know some people get to it while searching for this specific use case, but If you need to extract data from the Facebook Marketing API, you should use the Singer tap made for that.
Take a look at Tap-facebook and Target-csv.