2017-07-25 7 views
1

私はGAM(appsmarket/v2/userLicense)からのユーザーライセンス情報を知る必要があるシートアドオンを持っています。ユーザーは既にSheetsにログインしているので、OAuthを使用する必要はありませんでしたが、私は403("message":"Not authorized to access the application ID")を取得しています。 OAuthを使わずにApps Scriptからライセンスにアクセスする方法はありますか?これまでのコードはこれまで通りです: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()) 
} 

私はこのライブラリを使用する必要がありますか?

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()) 
} 
関連する問題