我的Oauth对吗?

时间:2016-12-18 01:31:21

标签: google-chrome-extension oauth

我的扩展已经有了Oauth大约一个月了,而且说实话,我不知道发生了什么。我试着看看谷歌API的统计数据,但没有。

我的问题是:

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

1 个答案:

答案 0 :(得分:1)

请查看Chrome的https://laravel.com/docs/5.3/pagination#converting-results-to-json指南。对于实际代码示例,请检查:

  1. Tutorial: OAuth演示。
  2. oauth_contacts演示。
  3. 同时检查gdocs。它提到了一种subscription guide的方式,可能对你的情况有所帮助。