我正在尝试将我的rails应用程序连接到trello API。我曾要求提供令牌和秘密 https://trello.com/app-key 我已经安装了红宝石宝石&ruby-trello'在我的gemfile中。
我需要在提交我的联系表格时生成一张trello卡片,其中包含提交的电子邮件,邮件的对象和邮件内容。这是我在contact_controller.rb中的create方法
def create
@contact = Contact.new(contact_params)
if @contact.save
redirect_to root_path
flash[:alert] = "Votre message a bien été envoyé à l'équipe TennisMatch, nous vous contacterons dans les plus brefs délais !"
Trello.configure do |config|
config.developer_public_key = ENV['PUBLIC_TRELLO_KEY']
config.member_token = ENV['MEMBER_TRELLO_TOKEN']
end
me = Trello::Member.find("david_geismar")
# find first board
board = me.boards.first
puts board.name
# puts "Lists: #{board.lists.map {|x| x.name}.join(', ')}"
# puts "Members: #{board.members.map {|x| x.full_name}.join(', ')}"
board.cards.each do |card|
puts "fu"
# puts "-- Actions: #{card.actions.nil? ? 0 : card.actions.count}"
# puts "-- Members: #{card.members.count}"
# puts "-- Labels: #{card.labels.count}"
end
else
render 'new'
end
end
我的application.yml文件如下所示:
development:
PUBLIC_TRELLO_KEY: "******"
MEMBER_TRELLO_TOKEN: "******"
但每次我提交联系表格时都会收到错误消息: 无效令牌
这里是实际的日志:
重定向到http://localhost:3000/ E,[2015-06-17T01:47:19.732876#11385]错误 - :[401获取https://api.trello.com/1/members/david_geismar]:无效令牌
475ms完成500内部服务器错误
Trello ::错误 - 令牌无效
:
ruby-trello(1.2.1)lib / trello / client.rb:99:in invoke_verb'
ruby-trello (1.2.1) lib/trello/client.rb:19:in
get'
ruby-trello(1.2.1)lib / trello / client.rb:44:in find'
ruby-trello (1.2.1) lib/trello/member.rb:33:in
find'
app / controllers / contacts_controller.rb:14:in create'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in
send_action'
actionpack(4.2.0)lib / abstract_controller / base.rb:198:在process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in
process_action'
actionpack(4.2.0)lib / abstract_controller / callbacks.rb:20:in block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in
call'
activesupport(4.2.0)lib / active_support / callbacks.rb:219:在block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in
块中的halting_and_conditional'
activesupport(4.2.0)lib / active_support / callbacks.rb:151:在block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in
块中暂停'
activesupport(4.2.0)lib / active_support / callbacks.rb:169:in block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in
_ run_callbacks'
activesupport(4.2.0)lib / active_support / callbacks.rb:734:在_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in
run_callbacks'
actionpack(4.2.0)lib / abstract_controller / callbacks.rb:19:在process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in
process_action'
actionpack(4.2.0)lib / action_controller / metal / instrumentation.rb:31:在block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in
块中的仪器'
activesupport(4.2.0)lib / active_support / notifications / instrumenter.rb:20:in instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in
instrument'
actionpack(4.2.0)lib / action_controller / metal / instrumentation.rb:30:在process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in
process_action'
activerecord(4.2.0)lib / active_record / railties / controller_runtime.rb:18:in process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in
进程'
actionview(4.2.0)lib / action_view / rendering.rb:30:在process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in
发送'
actionpack(4.2.0)lib / action_controller / metal / rack_delegation.rb:13:dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in
阻止行动'
actionpack(4.2.0)lib / action_dispatch / routing / route_set.rb:73:in dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in
serve'
actionpack(4.2.0)lib / action_dispatch / journey / router.rb:43:block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in
发送'
actionpack(4.2.0)lib / action_dispatch / routing / route_set.rb:802:in call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in
call!'
omniauth(1.2.2)lib / omniauth / strategy.rb:164:call'
warden (1.2.3) lib/warden/manager.rb:35:in
阻止通话'
warden(1.2.3)lib / warden / manager.rb:34:in call'
rack (1.6.0) lib/rack/etag.rb:24:in
来电'
rack(1.6.0)lib / rack / conditionalget.rb:38:in call'
rack (1.6.0) lib/rack/head.rb:13:in
call'
actionpack(4.2.0)lib / action_dispatch / middleware / params_parser.rb:27:in call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in
call'
rack(1.6.0)lib / rack / session / abstract / id.rb:225:在context'
rack (1.6.0) lib/rack/session/abstract/id.rb:220:in
电话'
actionpack(4.2.0)lib / action_dispatch / middleware / cookies.rb:560:在call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in
来电'
activerecord(4.2.0)lib / active_record / connection_adapters / abstract / connection_pool.rb:647:in call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in
call'
actionpack(4.2.0)lib / action_dispatch / middleware / callbacks.rb:29:in block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in
_ run_callbacks'
activesupport(4.2.0)lib / active_support / callbacks.rb:734:在_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in
run_callbacks'
actionpack(4.2.0)lib / action_dispatch / middleware / callbacks.rb:27:in call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in
call'
actionpack(4.2.0)lib / action_dispatch / middleware / remote_ip.rb:78:in call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in
protected_app_call'
better_errors(2.1.1)lib / better_errors / middleware.rb:79:in better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in
call'
actionpack(4.2.0)lib / action_dispatch / middleware / debug_exceptions.rb:17:in call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in
call'
railties(4.2.0)lib / rails / rack / logger.rb:38:in call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in
阻止通话'
activesupport(4.2.0)lib / active_support / tagged_logging.rb:68:in block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in
已标记'
activesupport(4.2.0)lib / active_support / tagged_logging.rb:68:in tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in
call'
quiet_assets(1.1.0)lib / quiet_assets.rb:27:in call_with_quiet_assets'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in
来电'
rack(1.6.0)lib / rack / methodoverride.rb:22:in call'
rack (1.6.0) lib/rack/runtime.rb:18:in
call'
activesupport(4.2.0)lib / active_support / cache / strategy / local_cache_middleware.rb:28:in call'
rack (1.6.0) lib/rack/lock.rb:17:in
call'
actionpack(4.2.0)lib / action_dispatch / middleware / static.rb:113:call'
rack (1.6.0) lib/rack/sendfile.rb:113:in
来电'
railties(4.2.0)lib / rails / engine.rb:518:call'
railties (4.2.0) lib/rails/application.rb:164:in
来电'
rack(1.6.0)lib / rack / content_length.rb:15:in call'
puma (2.11.1) lib/puma/server.rb:507:in
handle_request'
puma(2.11.1)lib / puma / server.rb:375:在process_client'
puma (2.11.1) lib/puma/server.rb:262:in
块中运行'
puma(2.11.1)lib / puma / thread_pool.rb:104:在spawn_thread中的`block'
答案 0 :(得分:3)
您可能没有使用正确的会员令牌。
'秘密'显示在https://trello.com/app-key页面上的不是会员令牌。
您可以通过在浏览器中授权您的应用并复制返回的字符串来获取成员令牌。使用以下URL:
read,write
为您提供完全访问权限never
以便您不需要续订,默认为30天token
可以复制到Rails配置的字符串'秘密'这里根本不用。它似乎只用于oAuth验证方法。
答案 1 :(得分:0)
放置在application.yml
中的环境变量不会自动填充在Rails环境中。您可能想看看dotenv gem,这使得这个超级容易的IMO。实际上,您可以将环境变量放在名为.env
的顶级文件中,并且gem处理它们在您的环境中安装它们。
否则,您可以在初始化程序中添加一些代码,以便将这些代码读入您的环境。
答案 2 :(得分:0)
您确定加载了application.yml
吗?
默认情况下未加载,您必须添加:
ENV.update YAML.load_file('config/application.yml')[Rails.env] rescue {}
到config/application.rb