【发布时间】:2015-04-01 09:12:46
【问题描述】:
问题已通过进度修改
来自服务器的“结果”值是我传回给客户端的唯一 url(不是我的域)(请参阅我的 Meteor.call 函数)。
如何将用户引导至此网址?。使用 iron:router Router.go(); 不起作用,因为它会将 url 附加到我的域。
当用户单击“getgoodreads”按钮时调用该方法。
服务器.js
var request = Npm.require('request');
var querystring = Npm.require('querystring');
Meteor.methods({
getGoodreads: function () {
request.post('http://www.goodreads.com/oauth/request_token', {
oauth: {
consumer_key: 'someKey',
consumer_secret: 'someSecretKey'
}
}, function (err, res, body) {
req_data = querystring.parse(body);
result= 'http://www.goodreads.com/oauth/authorize?' + querystring.stringify({oauth_token: req_data.oauth_token});
});
return result;
}
});
client.js
Template.profiles.events({
'click #goodreads': function (event) {
event.preventDefault();
Meteor.call('getGoodreads', function (error, result) {
if (error) {
console.log(error)
} else {
console.log(result);
Router.go(result);
}
});
}
});
我收到此错误:
*糟糕,客户端或服务器上似乎没有 url 的路由:"http://localhost:3000/oauth/authorize?oauth_token=IBR4tGXdAgQbEsqmxve5Q."
要重定向到的正确网址是:http://www.goodreads.com/oauth/authorize?oauth_token=IWDH8EWUhn1jtrjsQA
*
库
Router.route('/profile/', {
name: 'profile',
waitOn: function () {
return Meteor.subscribe('profile');
},
action: function () {
***maybe make the post function here?***
// this.ready() is true if all items returned from waitOn are ready
if (this.ready())
this.render('profile');
else
this.render('Loading');
}
});
*“结果”链接将用户带到 goodreads 页面,用户通过登录他们的 goodreads 帐户授予我访问其数据的权限。但是,由于此路线未在我的路线中定义,因此出现错误。之所以如此,是因为每个 url 都是唯一的。
【问题讨论】:
标签: redirect meteor request iron-router iron