I have a script that can obtain successfully from the Facebook oAuth API:
function getToken() {
var appId = "XXXXXX";
var clientSecret = "XXXXXXXXXXXX";
var url = "https://graph.facebook.com/oauth/access_token?client_id="+appId+"&client_secret="+clientSecret+"&grant_type=client_credentials";
var response = UrlFetchApp.fetch(url);
var queryResult = response.getContentText();
var token = queryResult.slice(13);
return(token);
}
The question is, that I prefer not to have my appId and clientSecret in the body of my script so is there a way where I can code this in without having my credentials in plain text?
2
Answers
For that you need to install latest facebook SDK which uses Namespace and protected methods to get facebook data using graph api. Below is an example I worked on :
Manually enter the keys and secret into the script editor as a “Script Property” (File > Project properties > Script properties) and then access them in the code using the Properties Service.
For example you could manually add:
Then access it in the code with
This technique works if you wanted to share the script on somewhere like Github, or if you only gave out view-access to the script in which case the script properties aren’t visible (you should not be able to see the SPs in this script). If you give edit access to others they’ll be able to see the SPs, but then you could use User Properties.