2016-09-25 8 views
0

今私は、私が持っている各コースの名前とセクションを取得するためにうまく動作するGoogleのクラスルームAPIを持っています。宿題を各コースのリストに入れたいです。これどうやってするの? Google APIのJavaScriptクライアントが既に(そのまだベータ版であるため)教室のAPIの機能を持っている場合Javascript Google Classroom API - コースの宿題を手に入れよう

// Your Client ID can be retrieved from your project in the Google 
    // Developer Console, https://console.developers.google.com 
    var CLIENT_ID = '<CLIENTID>'; 

    var SCOPES = ["https://www.googleapis.com/auth/classroom.courses.readonly"]; 

    /** 
    * Check if current user has authorized this application. 
    */ 
    function checkAuth() { 
    gapi.auth.authorize(
     { 
     'client_id': CLIENT_ID, 
     'scope': SCOPES.join(' '), 
     'immediate': true 
     }, handleAuthResult); 
    } 

    /** 
    * Handle response from authorization server. 
    * 
    * @param {Object} authResult Authorization result. 
    */ 
    function handleAuthResult(authResult) { 
    var authorizeDiv = document.getElementById('authorize-div'); 
    if (authResult && !authResult.error) { 
     // Hide auth UI, then load client library. 
     authorizeDiv.style.display = 'none'; 
     loadClassroomApi(); 
    } else { 
     // Show auth UI, allowing the user to initiate authorization by 
     // clicking authorize button. 
     authorizeDiv.style.display = 'inline'; 
    } 
    } 

    /** 
    * Initiate auth flow in response to user clicking authorize button. 
    * 
    * @param {Event} event Button click event. 
    */ 
    function handleAuthClick(event) { 
    gapi.auth.authorize(
     {client_id: CLIENT_ID, scope: SCOPES, immediate: false}, 
     handleAuthResult); 
    return false; 
    } 

    /** 
    * Load Classroom API client library. 
    */ 
    function loadClassroomApi() { 
    gapi.client.load('classroom', 'v1', listCourses); 
    } 

    /** 
    * Print the names of the first 10 courses the user has access to. If 
    * no courses are found an appropriate message is printed. 
    */ 
    function listCourses() { 
    var request = gapi.client.classroom.courses.list({ 
     pageSize: 10 
    }); 

    request.execute(function(resp) { 
     var courses = resp.courses; 

     if (courses.length > 0) { 
     for (i = 0; i < courses.length; i++) { 
      var course = courses[i]; 
      var div = document.createElement('div'); 
      div.className = 'class="col-md-4"'; 
      div.innerHTML = '<div class="col-md-4"> \ 
      <div class="jumbotron"> \ 
      <h2>' + course.name + '</h2> \ 
      <p>' + course.section + '</p> \ 
      </div> \ 
      </div> \ 
      </div>'; 
      document.getElementById('output').appendChild(div); 
     } 
     } else { 
     appendPre('No courses found.'); 
     } 

    }); 
    } 

    /** 
    * Append a pre element to the body containing the given message 
    * as its text node. 
    * 
    * @param {string} message Text to be placed in pre element. 
    */ 
    function appendPre(message) { 
    var pre = document.getElementById('output'); 
    var textContent = document.createTextNode(message + '\n'); 
    pre.appendChild(textContent); 
    } 
+0

私が宿題を手に入れることができたとしても? –

+0

クイックスタート(https://developers.google.com/classroom/quickstart/js)のすべての手順を実行しましたか?何が原因でエラーが発生しているのでしょうか? – Wade73

+0

どこに置くべきかわかりませんでした。 –

答えて

0

は、私が確認することはできませんが、

を呼び出そうとすることができます

は、私が現在持っています

gapi.client [classroom/classroom.courses] .courseWork.list({.. parameters ..}、function(){...コールバック...});

JSクライアントを使用せずに、REST APIをJavascriptで直接呼び出してください。

+0

OK、これを見ます –

関連する問題