1
  • I am trying at the moment to connect MasteryConnect data to Google Sheets using their API
  • I have a Secret and Consumer Keys, but I get an error.
  • I have installed the latest OAuth1 Library- https://github.com/gsuitedevs/apps-script-oauth1
  • Here is the documentation I was given
  • I also get an error on the "service.setProjectKey(PROJECT_KEY)" line ("TypeError: Cannot find function setProjectKey in object [object Object]. (line 34, file "Code")"
var REQUEST_TOKEN_URL = 'https://app.masteryconnect.com/oauth/request_token';
var REQUEST_TOKEN_URL = 'https://app.masteryconnect.com/oauth/request_token';
var ACCESS_TOKEN_URL = 'https://app.masteryconnect.com/oauth/access_token';
var AUTHORIZE_URL = 'https://app.masteryconnect.com/oauth/authorize';

var CONSUMER_KEY = '6--------------------------------------------a';
var CONSUMER_SECRET = '6----------------------------------I';
var PROJECT_KEY = 'M------------O';
var REDIRECT_URL = 'https://script.google.com/macros/d/1-----------------T/usercallback';


function listTeachers() {
  var service = getMasteryConnectService();
  if (service.hasAccess()) {
    var url = 'https://api.masteryconnect.com/teachers.json';
    var response = service.fetch(url);
    var teachers = JSON.parse(response.getContentText());
    for (var i = 0; i < teachers.length; i++) {
      Logger.log(teachers[i].text);
    }
  } else {
    var authorizationUrl = service.authorize();
    Logger.log('Please visit the following URL and then re-run the script: ' + authorizationUrl);
  }
}

function getMasteryConnectService() {
  var service = OAuth1.createService('MasteryConnect');
  service.setAccessTokenUrl(ACCESS_TOKEN_URL)
  service.setRequestTokenUrl(REQUEST_TOKEN_URL)
  service.setAuthorizationUrl(AUTHORIZE_URL)
  service.setConsumerKey(CONSUMER_KEY);
  service.setConsumerSecret(CONSUMER_SECRET);
  service.setProjectKey(PROJECT_KEY);
  service.setCallbackFunction('authCallback');
  service.setPropertyStore(PropertiesService.getScriptProperties());
  return service;
}

function authCallback(request) {
  var service = getMasteryConnectService();
  var isAuthorized = service.handleCallback(request);
  if (isAuthorized) {
    return HtmlService.createHtmlOutput('Success! You can close this page.');
  } else {
    return HtmlService.createHtmlOutput('Denied. You can close this page');
  }
}

0 Answers0