我正在撰写Google Apps脚本,通过他们的API访问可汗学院的学生信息。目前,我有一个脚本可以成功访问我的用户数据并列出我的学生'信息作为JSON数据。我可以访问他们的用户ID和密钥,但我不知道如何继续访问每周进度和练习摘要等信息。如何使用api / user / exercise切换OAuth以访问其帐户?任何帮助将不胜感激。代码如下。
var CONSUMER_KEY = 'my consumer key';
var CONSUMER_SECRET = 'my consumer secret';
var PROJECT_KEY = 'my project key';
function listExercises() {
var service = getKhanAcademyService();
if (service.hasAccess()) {
var response = service.fetch('https://www.khanacademy.org/api/v1/user/students');
var students = JSON.parse(response.getContentText());
Logger.log(students);
Logger.log("______________________________");
for (var i = 0; i < students.length; i++){
Logger.log(students[i].nickname + ": " + students[i].user_id);
Logger.log(students[i].student_summary.key);
//HERE I WANT TO ACCESS MORE DETAILED STUDENT INFORMATION, LIKE THEIR
//MASTERED SKILLS AND WEEKLY PROGRESS
}
} else {
var authorizationUrl = service.authorize();
Logger.log('Please visit the following URL and then re-run the script: ' + authorizationUrl);
}
}
function getKhanAcademyService() {
var service = OAuth1.createService('khanAcademy');
service.setAccessTokenUrl('https://www.khanacademy.org/api/auth2/access_token');
service.setRequestTokenUrl('https://www.khanacademy.org/api/auth2/request_token')
service.setAuthorizationUrl('https://www.khanacademy.org/api/auth2/authorize');
service.setConsumerKey(CONSUMER_KEY);
service.setConsumerSecret(CONSUMER_SECRET);
service.setCallbackFunction('authCallback');
service.setPropertyStore(PropertiesService.getScriptProperties());
service.setOAuthVersion('1.0a');
service.setParamLocation('uri-query');
return service;
}
function authCallback(request) {
var service = getKhanAcademyService();
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');
}
}