此代码在其他情况下有效,但我认为文件的设置是导致问题的原因,我不确定如何解决它。这是一项契约(Contract)工作,因此我无法更改 fil 的设置,并且我不知道如何修复此错误。
我从这里调用 OAuth 模块:
var common = require('common');
var OAuth2 = require('oauth2');
var google = require('google');
exports.init = function(app) {
app.get('/oauth/google', function(req, res) {
var gmailAuthObject =
new OAuth2(google.clientId,
google.clientSecret,
'',
'https://accounts.google.com/o/oauth2/auth',
'https://accounts.google.com/o/oauth2/token');
var redirectUrl = gmailAuthObject.getAuthorizeUrl(
{ redirect_uri:google.callbackRedirect,
scope:'https://www.google.com/m8/feeds',
response_type:'code',
access_type:'offline' });
res.redirect(redirectUrl);
});
app.get('/oauth/google/callback', function(req, res) {
var code = req.query.code;
var content = '<script>' +
'window.opener.SITENAME.setGoogleCode("' + code + '");' +
'window.close();' +
'</script>';
res.writeHeader(200, {"Content-Type": "text/html"});
res.end(content, 'utf-8');
});
// Other Networks...
/******************************************************************************/
};
在新的 OAuth2 上失败:CALL_NON_FUNCTION_AS_CONSTRUCTOR( native )
OAuth 模块作为每个函数的导出,例如 exports.OAuth2
。
我猜问题是因为它在 exports.init
内部,但我无法修复它。这里有什么想法或帮助吗?谢谢!
最佳答案
如果您使用this module ,看来你应该这样做(在你提供的代码的第二行):
var OAuth2 = require("oauth2").OAuth2;
关于javascript - CALL_NON_FUNCTION_AS_CONSTRUCTOR(原生)NodeJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9279401/