访问对象中的值。以它的名字命名

时间:2017-09-22 08:50:28

标签: javascript node.js facebook express

所以我正在玩创建Facebook聊天机器人。为了与Facebook交谈,我需要验证我拥有我在Webhooks面板中提供Facebook的URL。

我有一条看似

的明确路线
app.get('/api/verification', (req, res) => {
  // Send back hub.challenge
});

所以在我从Facebook回来的req对象看起来像:

{ 'hub.mode': 'subscribe',
   'hub.challenge': '178462834',
   'hub.verify_token': 'my_verify_token' }

为了实现此目的,我console.log req.query并将其取回。但我无法转到req.query.hub.challenge,因为undefined因为hub.challenge是值名称而获得<IfModule mod_expires.c> # Activate mod_expires for this directory ExpiresActive on # locally cache common image types for 7 days ExpiresByType image/jpg "access plus 7 days" ExpiresByType image/jpeg "access plus 7 days" ExpiresByType image/gif "access plus 7 days" ExpiresByType image/png "access plus 7 days" # cache CSS files for 24 hours ExpiresByType text/css "access plus 7 days" # chache JS files for 24 hours ExpiresByType application/javascript "access plus 7 days" </IfModule> <IfModule mod_rewrite.c> Options +FollowSymlinks # enable the rewrite engine RewriteEngine On # Set your root directory RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^freedom\.html$ /?item=0 [R=301,L] RewriteRule ^meet-new-people\.html$ /?item=1 [R=301,L] RewriteRule ^landscapes\.html$ /?item=2 [R=301,L] RewriteRule ^wildness\.html$ /?item=3 [R=301,L] RewriteRule ^hiking\.html$ /?item=4 [R=301,L] RewriteRule ^peaks\.html$ /?item=5 [R=301,L] RewriteRule ^paths\.html$ /?item=6 [R=301,L] RewriteRule ^getaway\.html$ /?item=7 [R=301,L] RewriteRule ^experiment-with\.html$ /?item=8 [R=301,L] RewriteRule ^rullini/freedom\.html$ /rullini/?item=0 [R=301,L] RewriteRule ^rullini/misterioso-bianco\.html$ /rullini/?item=1 [R=301,L] RewriteRule ^rullini/the-last-snow\.html$ /rullini/?item=2 [R=301,L] RewriteRule ^rullini/wildness\.html$ /rullini/?item=3 [R=301,L] RewriteRule ^rullini/the-green-mountains\.html$ /rullini/?item=4 [R=301,L] RewriteRule ^rullini/hiking\.html$ /rullini/?item=5 [R=301,L] RewriteRule ^rullini/sea-of-clouds\.html$ /rullini/?item=6 [R=301,L] </IfModule>

如果有值,我如何访问该值。在它的名字?

1 个答案:

答案 0 :(得分:3)

使用realpath

有关MDN

的更多信息