Facebook authentication in App Script

106 views
Skip to first unread message

Hashcrypt Hash

unread,
Aug 8, 2024, 7:41:22 AM8/8/24
to Google Apps Script Community
Hi,

In the app script, I want to add AuthType as OAUTH2 and implement Facebook authentication when users access the data studio. After that, I want to fetch the access token when the user comes back on callback after authentication.

Below is the codebase of app script

=> code.gs 

function getAuthType() {
    var cc = DataStudioApp.createCommunityConnector();
    return cc.newAuthTypeResponse()
        .setAuthType(cc.AuthType.OAUTH2)
        .setAuthUrl('https://www.facebook.com/dialog/oauth') // Your Facebook authorization endpoint
        .setClientId('********709369') // Replace with your App ID
        .setClientSecret('*********03284c09d3') // Replace with your App Secret
    .setScopes(['email', 'public_profile']) // Example scopes, adjust as needed
    .build();
}
var cc = DataStudioApp.createCommunityConnector();


function getConfig(request) {
  var cc = DataStudioApp.createCommunityConnector();
  var config = cc.getConfig();
 
  config.newInfo()
    .setId('instructions')
    .setText('Datablaster.io - Test');
  try{
      var accessToken = request.configParams.accessToken;
      Logger.log(accessToken);
  }catch (error) {
      // Handle the error, e.g., display an error message in the config
      config.newInfo()
        .setId('error')
        .setText('Error : ' + error.message);
      Logger.log('Error :', error);
    }

  config.setDateRangeRequired(false);
  return config.build();
}

function isAdminUser() {
  return true;
}

=> appscript.json

{
  "timeZone": "Etc/GMT",
  "dependencies": {},
  "runtimeVersion": "V8",
  "dataStudio": {
    "name": "Facebook Ads and Instagram Ads",
    "logoUrl": "****",
    "company": "Datablaster",
    "companyUrl": "*****",
    "addonUrl": "*****",
    "supportUrl": "****",
    "description": "******",
    "shortDescription": "****",
    "privacyPolicyUrl": "******",
    "termsOfServiceUrl": "*******",
    "authType": [
      "NONE"
    ],
    "feeType": [
      "FREE"
    ],
    "sources": [
      "Facebook_ads",
      "Meta_ads"
    ],
    "templates": {
      "default": "*****"
    }
  },
  "oauthScopes": [
  ],
  "urlFetchWhitelist": [
    "****",
    "*****",
  ]
}
Please provide proper documentation and information for how we can achieve this.

Thanks




Reply all
Reply to author
Forward
0 new messages