我有一個帖子函數,它在正文中返回一個oauth_token。在POST函數返回數據後,流星將用戶重定向到uri
我存儲了這個oauth_token值並附加它來完成uri。
如何在用戶接收到發佈請求的內容後將用戶重定向到uri?
我使用NPM包 '請求'
Server.js
Meteor.methods({
getGoodreads: function() {
var oauth = {
consumer_key: 'mykey',
consumer_secret: 'secretkey'
};
var url = 'http://www.goodreads.com/oauth/request_token'
request.post({url:url, oauth:oauth, json:true}, function (e, r, body) {
req_data = querystring.parse(body);
token = querystring.stringify({oauth_token: req_data.oauth_token});
var uri = 'http://www.goodreads.com/oauth/authorize?'+ token; // trying to direct user to this uri
});
}
});
client.js
Template.profiles.events({
'click #goodreads': function (event) {
event.preventDefault();
Meteor.call('getGoodreads', function (error, result) {
if (error) {
console.log(error)
} else {
Router.go(result); //if I can get the uri value back here then I direct the user to the uri here
}
});
}
});
已經收到的身體後,我因此具有組oauth_token這如上所示附加到uri。 然後我如何引導用戶到這個uri?我在設置一個回調函數方面並不是100%熟悉,似乎這是一種使用方法,因爲當用戶單擊頁面上的按鈕時,啓動POST函數。所以我只需要引導用戶,如果這個帖子函數運行,因爲uri依賴於oauth_token。
什麼是'app'?這個問題的答案取決於'app'定義的'req','res'是什麼。 – 2015-02-05 15:00:14
好問題,我認爲這是一些本地功能,當得到ПетърПетров的建議。我還沒有創建應用程序對象。我將刪除它。 – meteorBuzz 2015-02-05 15:29:01
那你怎麼接受用戶的請求?或者你沒有那麼遠?可能想看看'express'。 – 2015-02-05 15:54:50