0
我對此非常陌生,目前正在努力獲取OAuth 2.0令牌以用於Google Apps腳本以寫入Fusion Table。我使用的是Arun的Google Developers Live代碼,我似乎無法獲取訪問令牌。當我運行下面的doGet函數時,它給我一個「類型錯誤:無法讀取屬性」參數「來自未定義」。獲取OAuth2的參數錯誤
function doGet(e) {
var HTMLToOutput;
if(e.parameters.code){//if we get "code" as a parameter in, then this is a callback. we can make this more explicit
getAndStoreAccessToken(e.parameters.code);
HTMLToOutput = '<html><h1>Finished with oAuth</h1>You can close this window.</html>';
}
return HtmlService.createHtmlOutput(HTMLToOutput);
}
function getAndStoreAccessToken(code){
var parameters = {
method : 'post',
payload : 'client_id='+CLIENT_ID+'&client_secret='+CLIENT_SECRET+'&grant_type=authorization_code&redirect_uri='+REDIRECT_URL+'&code=' + code
};
var response = UrlFetchApp.fetch(TOKEN_URL,parameters).getContentText();
var tokenResponse = JSON.parse(response);
// store the token for later retrieval
UserProperties.setProperty(tokenPropertyName, tokenResponse.access_token);
}
任何幫助將不勝感激。