Home > Paid Traffic Sources > Facebook & Instagram

(script) FB Track total cost yesterday campaign automatic (1)


10-02-2015 04:18 PM #1 gianishere (Member)
(script) FB Track total cost yesterday campaign automatic

hi.
I made this little code so they can get the total cost of a campaign. With this information they can develop their own script and automate for see coherent statistics in your tracker

sure they will say that this code is irrelevant, but think of the possibilities. copy and paste your daily spending and run update spending is not the best way.
I share what I did.

I did the script to Thrive, but with some knowledge of php can adapt to any tracker.
with cronjobs rule can make it run at the end of the day

Code:
// Facebook variables
$fb->token 	= 'access token';
$fb->camp 	= 'id campaign';

// Thrive variables
$thrive->apiKey 	= 'xxxx';
$thrive->apiSecret 	= 'xx';
$thrive->base 		= 'domain.com/thrive';
$thrive->timeZone 	= 'your time zone. example: America/Lima';
$thrive->camp 		= 'id thrive campaign';
api: https://developers.facebook.com/docs.../insights/v2.4
for access_token https://developers.facebook.com/docs.../access-tokens

To obtain the Access_token you have to create an application (developers.facebook.com)
Code:
step 1:
https://www.facebook.com/dialog/oauth?client_id={app_id}&redirect_uri=http://domain.com/&scope=ads_management,manage_pages

enter this link, redirect to dominio.com/?code=XXXXXX
copy XXXXX


step 2:
https://graph.facebook.com/v2.4/oauth/access_token?client_id={app_id}&redirect_uri=http://domain.com/&client_secret={app_secret}&code=XXXXXX

return {"access_token":"YYYYYYYYYYYYYYYYYYYYY","token_type":"bearer"}
copy YYYYYYYYYYYYYYYYYYYYY

step 3: (access token long live)
https://graph.facebook.com/v2.4/oauth/access_token?grant_type=fb_exchange_token&client_id={app_id}&client_secret={app_secret}&fb_exchange_token=YYYYYYYYYYYYYYYYYYYYY

enter this link, copy access token final.
download
https://drive.google.com/file/d/0Bxv...ew?usp=sharing

I hope it helps someone, Greetings


Home > Paid Traffic Sources > Facebook & Instagram