Javascript Google Api中的奇数node.js行为
我正在编写一个小的node.js web应用程序,它需要Google API并使用OAuth2作为身份验证机制。在请求访问令牌时,我注意到了一些奇怪的事情——允许访问后接收到的“代码”将对象的类型更改为字符串。响应类型记录在“建筑物中的OAuth”之后 抱歉,如果这是一个重复的问题 路线:Javascript Google Api中的奇数node.js行为,javascript,node.js,google-api,Javascript,Node.js,Google Api,我正在编写一个小的node.js web应用程序,它需要Google API并使用OAuth2作为身份验证机制。在请求访问令牌时,我注意到了一些奇怪的事情——允许访问后接收到的“代码”将对象的类型更改为字符串。响应类型记录在“建筑物中的OAuth”之后 抱歉,如果这是一个重复的问题 路线: handle['/connect'] = requestHandlers.connect; handle['/oauth2callback'] = requestHandlers.oauth; 路由器: c
handle['/connect'] = requestHandlers.connect;
handle['/oauth2callback'] = requestHandlers.oauth;
路由器:
console.log("About to route a request for " + pathname);
if (typeof handle[pathname] === 'function'){
handle[pathname](response);
if (pathname === '/oauth2callback'){
handle[pathname](query);
}
} else {
console.log("No request handler found for " + pathname);
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("404 Not found");
response.end();
}
处理程序:
function connect(response){
console.log("Request Handler 'start' was called.");
auth.access(response);
}
function oauth(response){
console.log("OAuth in the building. This is the instance: ");
if(typeof response !== 'undefined'){
if(typeof response == "string"){
var code = response.split("code=").pop();
auth.exchange(code);
}else {
console.log("This response isn't ready until it is a string. It has these values: " + Object.getPrototypeOf(response));
}
}
}
身份验证:
function getAccess(response){
var url = authClient.generateAuthUrl({
access_type: 'offline',
scope: 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.readonly'
});
console.log("[Auth.js] This is the response received: " + Object.keys(response));
response.writeHead(302,{
"Location":url
});
response.end();
}
function exchangeToken(code){
authClient.getToken(code,function(err,tokens){
console.log("We got some tokens! " + tokens);
});
console.log("Authorized");
}
你能提供一段相关代码吗?@JonathanLonowski刚刚添加了一些!好吧,我想我弄错了。在我的路由器中,在第二个if语句之前有handle[pathname](response),但它应该在else{}旁边。