【问题标题】:How do I REconfigure Meteor's accounts-facebook, or where is Meteor's Facebook configuration?如何重新配置​​ Meteor 的帐户-facebook,或者 Meteor 的 Facebook 配置在哪里?
【发布时间】:2013-06-12 23:47:51
【问题描述】:

Meteor 的accounts-facebook 包非常容易设置。要输入 Facebook 应用程序 ID 和秘密令牌,我在浏览器中加载了我的流星网络应用程序,然后单击登录按钮,然后单击“配置 Facebook”,它要求我输入应用程序 ID 和秘密令牌等配置值。

现在我想更改它们,但不知道它们的存储位置。我没有在我的流星应用程序目录或子目录的任何文件中看到它们,也没有在任何地方的数据库中看到它们。

【问题讨论】:

  • Google login configuration 几乎在同一个地方 - 有趣的是,这个问题是在这个问题的前几天被问到的。

标签: facebook meteor


【解决方案1】:

配置数据存储在mongodb中。

如果你加载了

meteor mongo

然后使用db.meteor_accounts_loginServiceConfiguration.find() 你应该会看到你的配置数据

你也可以更新它!如果你回来了

{ "service" : "x", "appId" : "x", "secret" : "x", "_id" : "abc" }`

在同一个 mongo shell 中:

db.meteor_accounts_loginServiceConfiguration.update({_id:'abc'},
    {$set:{"appId" : <new app id>, "secret" : <new secret>}});

(使用您要编辑的服务配置中的 _id 字段。

在 Meteor 中,您可以改用它:

ServiceConfiguration.configurations.update({
    service:"facebook"
}, {
    $set: {
        <new params>
    }
});

注意要在流星中执行此操作,您需要添加此包:

meteor add service-configuration

【讨论】:

  • 多哈。看起来我没有以某种方式刷新数据库的集合? (我正在使用 Robomongo GUI)。正如你所描述的那样,它们在那里。谢谢!
  • 虽然了解数据的存储位置很有价值,但我发现下面的答案要好得多,因为它使用了可以从服务器代码轻松编写脚本的官方 API。
  • @oligofren 谢谢,我也更新了我的答案,因为该集合已再次重命名为 ServiceConfiguration
【解决方案2】:

为了详细说明 Kristoffer 的回答,这里是如何在运行时配置应用程序

/server/boot.js

configureFacebook = function(config) {
    // first, remove configuration entry in case service is already configured
    ServiceConfiguration.configurations.remove({
        service: "facebook"
    });

   ServiceConfiguration.configurations.insert({
        service: "facebook",
        appId: config.clientId,
        secret: config.secret
    });
};

// set the settings object with meteor --settings private/settings-local.json
var facebookConfig = Meteor.settings.facebook;
if(facebookConfig) {
    console.log('Got settings for facebook', facebookConfig)
    configureFacebook(facebookConfig);
}

这与一些在本地和生产环境中使用的设置文件结合使用:

/private/local-settings.json

{
    "facebook" : {
        "clientId": "330foobar",
        "secret": "52e1e247a5a1234klasdf087vasdff07"
    }
}

要在本地开发,我只需执行 meteor --settings private/local-settings.json 并将 facebook 的生产设置部署到我执行 meteor deploy --settings private/prod-settings.json 的生产服务器。

【讨论】:

  • @ShankarRegmi 似乎是合法的,但我已经一年没有使用 Meteor,所以我不能保证。谢谢你的建议:)
  • P.S.如果可行,@ShankarRegmi,只需编辑我的答案并改进它。
【解决方案3】:

这个怎么样:

Accounts.loginServiceConfiguration.insert({
  service: "facebook",
  appId: "1292962797",
  secret: "75a730b58f5691de5522789070c319bc"
});

在这里找到:http://docs.meteor.com/#meteor_loginwithexternalservice

【讨论】:

  • 我看到了,谢谢(顺便说一句,如果我使用 {{loginButtons}} handlebars 助手,我不知道该代码会去哪里)。但我想知道配置文件在哪里,然后在那里更改。
  • 为什么不采用支持/记录的方式呢?该代码将在服务器上运行,介于 if (Meteor.isServer) { //HERE } 或 server/ 目录中的 .js 文件之间。
  • 此解决方案需要更新以反映当前的 Meteor。运行:'meteor add service-configuration' 现在的功能是:'ServiceConfiguration.configurations.insert',它是 appID 而不是“clientId”
  • @LloydDewolf:谢谢你现在让我!花了太多时间挠头:)我更新了答案
  • @LloydDewolf 谢谢!!谢谢!。
【解决方案4】:

这只会在启动时删除所有服务并根据您的 settings.json (meteor --settings settings.json) 重新插入它们 咖啡脚本等价物:

@privateSettings = Meteor.settings.private

for s in privateSettings.services
  ServiceConfiguration.configurations.remove service: s.service
  ServiceConfiguration.configurations.insert s

settings.json 中存储的设置:

{
  "private": {
    "services": [{
        "service": "google",
        "clientId": "yourappid.apps.googleusercontent.com",
        "secret": "yoursecret"
    },{ 
        "service": "twitter",
        "consumerKey": "yourconsumerkey",
        "secret": "yoursecret"
    },{
        "service": "facebook",
        "appId": "yourappid",
        "secret": "yoursecret"
    }],
  }
}

【讨论】:

    【解决方案5】:

    如果您的应用程序中还没有太多数据,只需运行:

    meteor reset
    

    这将清除应用程序的所有 Mongo 数据。

    【讨论】:

      【解决方案6】:

      [注意:对于 Meteor >= 1.2.2]

      Meteor 官方文档here 解释了如何做到这一点。

      添加service-configuration包(否则不能使用ServiceConfiguration):

      $ meteor add service-configuration
      

      那你可以把这个放到Meteor.startup:

      Meteor.startup(function () {
      
        // Set Facebook app configurations
        ServiceConfiguration.configurations.upsert({ 
          service: "facebook" 
        }, {
          $set: {
            appId: 'YOUR_APP_ID',
            secret: 'YOUR_APP_SECRET'
          }
        });
      
        return;
      });
      

      在 settings.json 中外部化 Facebook 配置

      也许最终的解决方案是将 Facebook 应用的配置放入设置文件中

      /settings.json
      

      像这样:

      {
        "facebook" : {
          "appId": "APP_ID",
          "secret": "APP_SECRET"
        }
      }
      

      然后你必须启动你的 Meteor 应用程序

      $ meteor --settings settings.json
      

      为了加载设置文件。

      最后,您可以从设置文件中的Meteor.startup 中加载 Facebook 配置:

      Meteor.startup(function () {
      
        // Load and set Facebook app configurations
        var facebookConfig = Meteor.settings.facebook;
        ServiceConfiguration.configurations.upsert({ 
          service: "facebook" 
        }, {
          $set: {
            appId: facebookConfig.appId,
            secret: facebookConfig.secret
          }
        });
      
        return;
      });
      

      【讨论】:

        猜你喜欢
        • 2014-11-29
        • 1970-01-01
        • 2015-11-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-10
        • 2014-03-09
        • 1970-01-01
        • 2017-02-17
        相关资源
        最近更新 更多