0
我已經在我的擴展中使用了Oauth大約一個月的時間,並且完全誠實地說,我不知道發生了什麼。我試圖從谷歌API的統計,但沒有任何。我的Oauth是否正確?
所以我的問題是:
有什麼錯我的代碼?我在做什麼「TRIAL_PERIOD_DAYS」錯誤?
chrome.identity.getAuthToken({
interactive: true
}, function(token){
var CWS_LICENSE_API_URL = 'https://www.googleapis.com/chromewebstore/v1.1/userlicenses/fcjhennclbpgegahkbbnndbhmlhkdabe';
var req = new XMLHttpRequest();
req.open('GET', CWS_LICENSE_API_URL + chrome.runtime.id);
req.setRequestHeader('Authorization', 'Bearer ' + token);
req.onreadystatechange = function() {
if (req.readyState == 4) {
var license = JSON.parse(req.responseText);
console.log(license);
verifyAndSaveLicense(license);
}
}
req.send();
console.log(TRIAL_PERIOD_DAYS);
var licenseStatus;
if (license.result && license.accessLevel == "FULL") {
console.log("Fully paid & properly licensed.");
licenseStatus = "FULL";
} else if (license.result && license.accessLevel == "FREE_TRIAL") {
var daysAgoLicenseIssued = Date.now() - parseInt(license.createdTime, 10);
daysAgoLicenseIssued = daysAgoLicenseIssued/1000/60/60/24;
if (daysAgoLicenseIssued <= TRIAL_PERIOD_DAYS) {
console.log("Free trial, still within trial period");
licenseStatus = "FREE_TRIAL";
} else {
console.log("Free trial, trial period expired.");
licenseStatus = "FREE_TRIAL_EXPIRED";
window.open('https://chrome.google.com/webstore/detail/premium-roulette/fcjhennclbpgegahkbbnndbhmlhkdabe');
}
} else {
console.log("No license ever issued.");
licenseStatus = "NONE";
}
});
我剛剛意識到問題在於我沒有設置「TRIAL_PERIOD_DAYS」。 –