Is my Oauth right?



我已经在扩展程序上已经有一个月了一个月,说实话,我不知道发生了什么。我尝试查看Google API的统计信息,但有任何统计信息。

所以我的问题是:

我的代码有问题吗?我在" afir_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";
}
});

请检查教程:Chrome的OAuth指南。对于实际代码样本,请检查以下内容:

  1. oauth_contacts演示。
  2. gdocs演示。

还检查订阅指南。它提到了一种验证付款和提供免费试用的方式,这可能有助于您的情况。

最新更新