Coder Social home page Coder Social logo

Comments (4)

fredericharnois avatar fredericharnois commented on May 27, 2024

Hi @alexjs-dev

Glad this project can help out!

Could you give me more information as to what is being passed in FIELDS?

Also, just to be sure, in your actual code, are there backticks (`) around the URL?

Thanks!

from facebook-ads-reporting-google-apps-script.

Alex-git-code avatar Alex-git-code commented on May 27, 2024

Hi @fredericharnois ,

Thanks for your reply.
Yes i have backticks (`) around the URL, i don't know why are not displayed here.
Please see my code below(I will not display here the right value for token and ad account id for security reasons):

// ad account ID
const AD_ACCOUNT_ID = '102042577';

// ad, adset, campaign, account
const LEVEL = 'ad';

// https://developers.facebook.com/docs/marketing-api/insights/parameters#fields
const FIELDS = 'campaign_name, adset_name, ad_name, date_preset, reach, impressions, spend, cpm, inline_link_clicks, inline_link_click_ctr, cpc, conversions, conversion_values, cost_per_conversion, purchase_roas, actions';

// https://developers.facebook.com/docs/marketing-api/insights/parameters#param
const TIME_RANGE = 'yesterday';

// user access token linked to a Facebook app
const TOKEN = 'EAAZBMSK3S'

// number of days from 1 to 90
const TIME_INCREMENT = 1;

// https://developers.facebook.com/docs/marketing-api/insights/parameters#param
const FILTERING = [{'field':'action_type','operator':'IN','value':['offsite_conversion.fb_pixel_purchase', 'value' ,'link_click']}]

// DO NOT MODIFY ANYTHING BELOW //

function requestFacebookReport() {

// Builds the Facebook Ads Insights API URL
const facebookUrl = https://graph.facebook.com/v6.0/act_${AD_ACCOUNT_ID}/insights?level=${LEVEL}&fields=${FIELDS}&date_preset=${TIME_RANGE}&access_token=${TOKEN}&time_increment=${TIME_INCREMENT}&limit=5000;
const encodedFacebookUrl = encodeURI(facebookUrl);

const options = {
'method' : 'post'
};

// Fetches & parses the URL
const fetchRequest = UrlFetchApp.fetch(encodedFacebookUrl, options);
const results = JSON.parse(fetchRequest.getContentText());

// Caches the report run ID
const reportId = results.report_run_id;
const cache = CacheService.getScriptCache();
const cached = cache.get('campaign-report-id');

if (cached != null) {
cache.put('campaign-report-id', [], 1);
Utilities.sleep(1001);
cache.put('campaign-report-id', reportId, 21600);
} else {
cache.put('campaign-report-id', reportId, 21600);
};

Logger.log(cache.get('campaign-report-id'));
}

from facebook-ads-reporting-google-apps-script.

Alex-git-code avatar Alex-git-code commented on May 27, 2024

I discovered the error, i place date_preset as a field. Thanks anyway. i will close the issue

from facebook-ads-reporting-google-apps-script.

pranvirsingh avatar pranvirsingh commented on May 27, 2024

@Alex-git-code Can you please tell me what did you did exactly to make your code work?

from facebook-ads-reporting-google-apps-script.

Related Issues (20)

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.