小编Jen*_*010的帖子

检测 chrome 是否正在加载缓存页面?

这是其中之一,“我需要一种解决方法,以便在项目启动后不必忍受用户 1000 年的争​​吵”类型的问题:

我有一种情况,每当有人启动 Chrome 时,我都需要重新加载我的网站,而上次关闭浏览器时却没有关闭标签页。我们正在现代、MEAN 堆栈环境中重建一个古老的站点,我只知道当它启动时我会收到投诉。

换句话说(危险:伪代码)-

if client closed chrome with site open
  reauthenticate user
  redirect to home page
Run Code Online (Sandbox Code Playgroud)

我可以通过快速路由和护照身份验证完成最后两位,但是我如何检测客户端是否从他们的末端加载缓存页面?

javascript google-chrome browser-cache express angularjs

5
推荐指数
1
解决办法
434
查看次数

Passport.js / Google OAuth2 策略 - 如何在登录时使用令牌进行 API 访问

我使用 Passport.js 通过他们的域 Google 帐户登录用户。这很好用,但现在我需要让这个应用程序访问一些 Google API(驱动器、工作表等)。

当用户登录时,日志中会出现一条消息,这使得护照看起来拥有所有必需的信息:

info: [06/Jun/2019:21:24:37 +0000] "302 GET /auth/callback?code=** USER ACCESS TOKEN HERE **&scope=email%20profile%20https://www.googleapis.com/auth/drive.file%20https://www.googleapis.com/auth/spreadsheets%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/drive HTTP/1.1" [46]
Run Code Online (Sandbox Code Playgroud)

这是通过通过 Passport.authenticate() 传递附加范围来实现的,它向用户提供“授予此应用程序对您 Google 帐户上这些内容的访问权限吗?”的信息。屏幕 :

//Initial auth call to Google
router.get('/',
  passport.authenticate('google', {
    hd: 'edmonds.wednet.edu',
    scope: [
      'email',
      'profile',
      'https://www.googleapis.com/auth/drive',
      'https://www.googleapis.com/auth/drive.file',
      'https://www.googleapis.com/auth/spreadsheets'
    ],
    prompt: 'select_account'
  })
);
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用以下内容调用 API 时:

const {google} = require('googleapis');
const sheets = google.sheets({version: 'v4', auth});

router.post('/gsCreate', function(req,res,next){

  sheets.spreadsheets.create({
    // Details here.....
  });

});
Run Code Online (Sandbox Code Playgroud)

我除了错误什么也没有得到(当前的错误是debug: authClient.request is not a function

我的问题是:我是否可以使用这样的设置,要求用户登录并授予权限一次,然后以某种方式通过护照将其保存到用户会话中?

javascript google-api express google-oauth passport.js

5
推荐指数
2
解决办法
3504
查看次数

Google 应用程序脚本 - 循环中断

我正在使用 Google 应用程序脚本,似乎搞砸了我的一个 for 循环。我确定我在这里遗漏了一些微不足道的东西,但我似乎无法发现它。

代码片段:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var lastRow = sheets[3].getLastRow();
var zw = sheets[3].getRange(2, 1, lastRow - 1, 26).getValues();
for (var j = 0; j < zw.length; ++j) {
    if (zw[j][9] === 'Yes') {
        var masterEmail = [];
        var firstLetterLastName = [];
        var first2Letter = [];
        var masterEmail.push(zw[j][22]);
        var firstLetterLastName.push(zw[j][1].charAt(0).toLowerCase());
        var first2Letter.push(zw[j][1].charAt(0).toLowerCase() + zw[j][1].charAt(1).toLowerCase());
        //The rest of the function follows...
    }
}
Run Code Online (Sandbox Code Playgroud)

什么不工作:

for 循环不会增加。在调试器中运行代码时,var j 的值保持为 0.0,而函数的其余部分仅根据 zw 的 0 位置的值运行。 …

javascript loops for-loop google-sheets google-apps-script

0
推荐指数
1
解决办法
2707
查看次数