質問は進行によって変更されました
サーバーからの「結果」の値は、クライアントに返す一意の URL (私のドメインではない) です (私の Meteor.call 関数を参照してください)。
ユーザーをこの URL に誘導するにはどうすればよいですか? . 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."
リダイレクト先の正しい URL は次のとおりです。 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 が一意であるためです。