2017-07-25 116 views
1

我有一张表格插件,我需要知道GAM的用户许可证信息(appsmarket/v2/userLicense)。由于用户已经登录到表格,我不期望需要使用OAuth,但我得到了403("message":"Not authorized to access the application ID")。有没有办法从Apps Script访问许可而不使用OAuth?这里是我的代码到目前为止:如何从Apps脚本(用于表单附件)访问Google Apps Marketplace UserLicense?

function testGetLicense(query) { 
    var options = { 
    'method' : 'get', 
    'contentType': 'application/json', 
    'muteHttpExceptions' : true 
    }; 
    var url = 'https://www.googleapis.com/appsmarket/v2/userLicense/1234/[email protected]' 
    res = UrlFetchApp.fetch(url, options); 
    Logger.log(res.getContentText()) 
} 

如果我需要使用OAuth,我应该使用这个库吗?

https://github.com/googlesamples/apps-script-oauth2

回答

1

尝试通过OAuth令牌的标头。

function testGetLicense(query) { 
    var options = { 
    'method' : 'get', 
    'contentType': 'application/json', 
     'headers': { 
     "Authorization": "Bearer " + ScriptApp.getOAuthToken() 
     }, 
    'muteHttpExceptions' : true 
    }; 
    var url = 'https://www.googleapis.com/appsmarket/v2/userLicense/1234/[email protected]' 
    res = UrlFetchApp.fetch(url, options); 
    Logger.log(res.getContentText()) 
}