我正在尝试获取经过身份验证的Facebook用户的个人资料图片,以便在Meteor应用程序中使用.我尝试了以下内容
Meteor.publish("facebook_avatar_url", function() {
return Meteor.users.find({_id: this.userId}, {fields: {
'services.facebook.id': 1,
'services.facebook.name': 1,
'services.facebook.gender': 1,
'services.facebook.picture': 1,
'services.facebook.picture.data': 1,
'services.facebook.picture.data.url': 1
}});
});
Run Code Online (Sandbox Code Playgroud)
它只返回id,name和gender.这似乎是我想要的,以及推荐的解决方案.唯一的问题是没有关于用户图片的数据被返回.
我尝试将以下内容添加到server/server.js,根据其他帖子的建议,但它a)似乎不是推荐的方法,而b)似乎没有做任何事情.所以,它似乎是一个死胡同,但有人似乎认为它可以用于获取配置文件图片加载.
var getFbPicture;
Accounts.loginServiceConfiguration.remove({
service: "facebook"
});
Accounts.onCreateUser(function(options, user) {
if (options.profile) {
options.profile.picture = getFbPicture(user.services.facebook.accessToken);
user.profile = options.profile;
}
return user;
});
getFbPicture = function(accessToken) {
var result;
result = Meteor.http.get("https://graph.facebook.com/me", {
params: {
access_token: accessToken,
fields: 'picture'
}
});
if (result.error) {
throw result.error;
}
return result.data.picture.data.url;
};
Run Code Online (Sandbox Code Playgroud)
所以,我有点不确定在这一点上要走哪条路.这是否需要在Facebook Graph API上设置权限?或者在Facebook应用程序上?我是否在发布功能中出现了错误的语法?我是否需要重新访问onCreateUser函数?
有人想出使用Meteor.js来检测托管环境的语法或模式吗?我有Heroku buildpacks工作,并有一个开发/生产环境,但我有点想知道如何让我的应用程序检测它正在运行的环境.
有没有办法让node.js检测它正在运行哪个端口?我希望可能有像app.address().port这样的低级别东西,但这似乎不起作用......
编辑:这是适合我的解决方案.请注意,需要在服务器上运行以下内容,因此需要将其包含在server\server.js或类似文件中.
if (Meteor.is_server) {
Meteor.startup(function () {
// we want to be able to inspect the root_url, so we know which environment we're in
console.log(JSON.stringify(process.env.ROOT_URL));
// in case we want to inspect other process environment variables
//console.log(JSON.stringify(process.env));
});
}
Run Code Online (Sandbox Code Playgroud)
还创建了以下内容:
Meteor.methods({
getEnvironment: function(){
if(process.env.ROOT_URL == "http://localhost:3000"){
return "development";
}else{
return "staging";
}
}
});
Run Code Online (Sandbox Code Playgroud)
在客户端允许以下内容:
Meteor.call("getEnvironment", function (result) {
console.log("Your application is running in the " + result + "environment.");
});
Run Code Online (Sandbox Code Playgroud)
谢谢Rahul!
有人想出使用Meteor.js在窗口调整大小上重新渲染模板的语法吗?我试过做一个Meteor.flush(),但这似乎不是正确的方法...... :(
window.onresize = function(){
Meteor.flush();
};
Run Code Online (Sandbox Code Playgroud) 救命!
我已经和Meteor合作了大约两个月了,而且在我的OSX家庭环境中,一切都在顺利进行.但是我最近把一些代码带到了我们的Windows 7环境中工作,而Meteor在Windows上的表现并不一样.
具体来说,代码捆绑不断变得笨拙.当我对代码库进行更改时,不是刷新旧的.meteor/local目录,而是重新绑定应用程序,它会在服务器控制台中向我发送ENOTEMPTY异常.如果我在任务资源管理器中暂停mongod进程并手动删除.meteor/local目录,我可以重新启动应用程序,它将使用新的代码更改捆绑和部署应用程序.
Running on: http://localhost:3000/
No dependency info in bundle. Filesystem monitoring disabled.
Errors prevented startup:
Exception while bundling application:
Error: ENOTEMPTY, directory not empty 'c:\Users\Abigail\My Documents\GitHub\canvas tracker\.meteor\local\build\server'
at Object.fs.rmdirSync (fs.js:456:18)
at Object.module.exports.rm_recursive (c:\Program Files (x86)\Meteor\app\lib\files.js:256:10)
at c:\Program Files (x86)\Meteor\app\lib\files.js:254:15
at Array.forEach (native)
at Function._.each._.forEach (c:\Program Files (x86)\Meteor\lib\node_modules\underscore\underscore.js:79:11)
at Object.module.exports.rm_recursive (c:\Program Files (x86)\Meteor\app\lib\files.js:252:9)
at _.extend.write_to_directory (c:\Program Files (x86)\Meteor\app\lib\bundler.js:493:11)
at Object.exports.bundle (c:\Program Files (x86)\Meteor\app\lib\bundler.js:685:12)
at exports.run.restart_server (c:\Program Files (x86)\Meteor\app\meteor\run.js:615:26)
at c:\Program Files (x86)\Meteor\app\meteor\run.js:726:9
Please fix the problem and restart. …
Run Code Online (Sandbox Code Playgroud) 所以,我正在开发Mac Mini,使用WebStorm与Meteor应用程序大惊小怪.我发现WebStorm趋于缓慢,并且不断尝试索引事物.我有4个RAM,其中791M似乎在任何时候分配给WebStorm.我的磁盘驱动器是500GB,我确保总是至少有20%到30%的可用空间.
所以,一些问题...... Meteor的捆绑过程是否导致WebStorm进行索引?有没有办法优化索引?让它运行频率降低?或许忽略.meteor目录?20%的可用RAM是否适合分配给WebStorm进行Meteor开发?人们可以推荐其他任何可以优化WebStorm的东西,所以它不是那么迟钝吗?
提前感谢任何建议!