{"id":5839,"date":"2020-02-14T23:10:04","date_gmt":"2020-02-14T14:10:04","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=5839"},"modified":"2020-02-14T23:10:04","modified_gmt":"2020-02-14T14:10:04","slug":"node-js%e3%81%a7twitter%e3%81%ab%e6%8a%95%e7%a8%bf%e3%81%99%e3%82%8b%ef%bc%88bit-ly%e3%81%a7%e7%9f%ad%e7%b8%aeurl%e3%82%82%e3%81%a4%e3%81%8f%e3%82%8a%e3%81%be%e3%81%99%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=5839","title":{"rendered":"Node.js\u3067Twitter\u306b\u6295\u7a3f\u3059\u308b\uff08Bit.ly\u3067\u77ed\u7e2eURL\u3082\u3064\u304f\u308a\u307e\u3059\uff09"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001<code>Node.js<\/code>\u306e\u9ad8\u901f\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u304a\u6c17\u306b\u5165\u308a\u306b\u306a\u3063\u3066\u304d\u305f\u4eca\u65e5\u3053\u306e\u9803\u3067\u3059\u3002<\/p>\n<p>\u3068\u306f\u3044\u3048\u3001\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e<code>Express<\/code>\u306f\u30df\u30cb\u30de\u30eb\u306a\u8a2d\u8a08\u306a\u306e\u3067\u3001\u3082\u3063\u3068<code>Laravel<\/code>\u306e\u3088\u3046\u306b\u300c\u3044\u305f\u308c\u308a\u3064\u304f\u305b\u308a\u300d\u306b\u306a\u308c\u3070\u3001\u4eba\u6c17\u306b\u306a\u308b\u3068\u601d\u3046\u306e\u3067\u3059\u304c\u3001\u307e\u3060\u3082\u3046\u5c11\u3057\u6642\u9593\u304c\u304b\u304b\u308b\u304b\u3001\u3082\u3057\u304f\u306f<code>Laravel<\/code>\u306e\u3088\u3046\u306a\u30b2\u30fc\u30e0\u30c1\u30a7\u30f3\u30b8\u30e3\u30fc\u304c\u73fe\u308c\u308b\u306e\u304b\u306a\u3001\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u305d\u3093\u306a\u4e2d\u3001\u3042\u308b\u958b\u767a\u3067\u300c<strong>\u3046\u30fc\u3093\u30fb\u30fb\u30fb\u306a\u304f\u3066\u3082\u3044\u3044\u3051\u3069\u3001\u3042\u308c\u3070\u5b09\u3057\u3044\u3088\u306d\ud83d\ude0a<\/strong>\u300d\u3068\u3044\u3046\u6a5f\u80fd\u306b\u906d\u9047\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u308c\u306f\u3001<\/p>\n<p><strong style=\"font-size: 35px;\">\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u3088\u308bTwitter\u3078\u306e\u6295\u7a3f<\/strong><\/p>\n<p>\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u6a5f\u80fd\u306f\u3001\u4ee5\u524d\u300c<a href=\"https:\/\/blog.capilano-fw.com\/?p=5226\">Laravel\u306b\u30c7\u30fc\u30bf\u767b\u9332\u3055\u308c\u305f\u3089Twitter\u306b\u6295\u7a3f\u3059\u308b<\/a>\u300d\u3068\u3044\u3046\u8a18\u4e8b\u3067<code>Laravel<\/code>\u7248\u3068\u3057\u3066\u306f\u3059\u3067\u306b\u304a\u5c4a\u3051\u3057\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306f\u3053\u306e<code>Node.js<\/code>\u7248\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3082\u3001\u524d\u56de\u3068\u5168\u304f\u540c\u3058\u3060\u3068\u9762\u767d\u304f\u306a\u3044\uff08\u305d\u3057\u3066\u305d\u308c\u306b\u52a0\u3048\u3066\u3001URL\u306e\u30af\u30ea\u30c3\u30af\u72b6\u6cc1\u3082\u77e5\u308a\u305f\u3044\u3068\u3044\u3046\u8981\u671b\u304c\u3042\u3063\u305f\u306e\u3067\uff09<a href=\"https:\/\/bitly.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Bit.ly<\/a>\u306e\u77ed\u7e2eURL\u3092\u542b\u3081\u305f\u30c4\u30a4\u30fc\u30c8\u3092\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3405 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18.png\" alt=\"\" width=\"310\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18.png 310w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18-291x300.png 291w\" sizes=\"auto, (max-width: 310px) 100vw, 310px\" \/><\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Node.js 8<\/p>\n<h1>\u5fc5\u8981\u306a\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b<\/h1>\n<p>\u5b9f\u969b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u5165\u308b\u524d\u306b\u3001\u5148\u306b<code>Twitter<\/code>\u3068<code>Bit.ly<\/code>\u304b\u3089\u30c8\u30fc\u30af\u30f3\u306a\u3069\u5fc5\u8981\u306a\u60c5\u5831\u3092\u53d6\u5f97\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>Twitter\u304b\u3089\u5fc5\u8981\u306a\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b<\/h2>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089Twitter\u306b\u6295\u7a3f\u3092\u3059\u308b\u5834\u5408\u3001\u5fc5\u8981\u306b\u306a\u3063\u3066\u304f\u308b\u306e\u306f\u4ee5\u4e0b\u306e\uff14\u3064\u3067\u3059\u3002<\/p>\n<ul>\n<li>consumer_key<\/li>\n<li>consumer_secret<\/li>\n<li>access_token_key<\/li>\n<li>access_token_secret<\/li>\n<\/ul>\n<p>\u203b\u3053\u308c\u3089\u306e\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u306f\u3001<a href=\"https:\/\/blog.capilano-fw.com\/?p=5226#api_key_n_access_token\" target=\"_blank\" rel=\"noopener noreferrer\">\u30c4\u30a4\u30c3\u30bf\u30fc\u3067API\u30ad\u30fc\u3068\u30a2\u30af\u30bb\u30b9\u30fb\u30c8\u30fc\u30af\u30f3\u3092\u53d6\u5f97\u3059\u308b<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>Bit.ly\u304b\u3089\u5fc5\u8981\u306a\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b<\/h2>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089Bit.ly\u3092\u901a\u3057\u3066\u77ed\u7e2eURL\u3092\u4f5c\u308b\u306b\u306f\u3001\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u3092\u53d6\u5f97\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u9806\u3092\u8ffd\u3063\u3066\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<p>\u307e\u305a\u306f\u3001<a href=\"https:\/\/bitly.com\/a\/sign_in\" target=\"_blank\" rel=\"noopener noreferrer\">\u30ed\u30b0\u30a4\u30f3\u30d5\u30a9\u30fc\u30e0<\/a>\u304b\u3089<code>Bit.ly<\/code>\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u753b\u9762\u53f3\u4e0a\u306b\u30a2\u30ab\u30a6\u30f3\u30c8\u60c5\u5831\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u30e1\u30cb\u30e5\u30fc\u3092\u8868\u793a\u3055\u305b\u3001\u300c<strong>Profile Settings<\/strong>\u300d\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5848\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/node_twitter_1.png\" alt=\"\" width=\"409\" height=\"307\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/node_twitter_1.png 409w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/node_twitter_1-300x225.png 300w\" sizes=\"auto, (max-width: 409px) 100vw, 409px\" \/><\/p>\n<p>\u3059\u308b\u3068\u3001\u3055\u3089\u306b\u30e1\u30cb\u30e5\u30fc\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u300c<strong>Generic Access Token<\/strong>\u300d\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5847\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/node_twitter_2.png\" alt=\"\" width=\"280\" height=\"453\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/node_twitter_2.png 280w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/node_twitter_2-185x300.png 185w\" sizes=\"auto, (max-width: 280px) 100vw, 280px\" \/><\/p>\n<p>\u6b21\u306b\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u805e\u304b\u308c\u308b\u306e\u3067\u3001\u30ed\u30b0\u30a4\u30f3\u306e\u3068\u304d\u306b\u4f7f\u3063\u305f\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5846\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/node_twitter_3.png\" alt=\"\" width=\"282\" height=\"361\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/node_twitter_3.png 282w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/node_twitter_3-234x300.png 234w\" sizes=\"auto, (max-width: 282px) 100vw, 282px\" \/><\/p>\n<p>\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u529b\u3057\u305f\u3089\u3001\u753b\u9762\u53f3\u4e0b\u306b\u300c<strong>\u30c8\u30fc\u30af\u30f3\u4f5c\u6210<\/strong>\u300d\u30dc\u30bf\u30f3\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u3053\u308c\u3092\u30af\u30ea\u30c3\u30af\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5845\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/node_twitter_4.png\" alt=\"\" width=\"272\" height=\"58\" \/><\/p>\n<p>\u3059\u308b\u3068\u3001\u4f5c\u6210\u3055\u308c\u305f\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u304c\u753b\u9762\u4e2d\u592e\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5844\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/02\/node_twitter_5.png\" alt=\"\" width=\"291\" height=\"130\" \/><\/p>\n<p>\u3053\u306e\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u306f\u3001\u5f8c\u3067\u4f7f\u3044\u307e\u3059\u306e\u3067\u3001\u5927\u4e8b\u306b\u4fdd\u7ba1\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u5fc5\u8981\u306anpm\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/h1>\n<p>\u6b21\u306b\u3001<code>Twitter<\/code>\u3068<code>Bit.ly<\/code>\u3067\u5fc5\u8981\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\uff12\u3064\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>npm i --save twitter<\/strong><\/pre>\n<pre><strong>npm i --save node-bitlyapi<\/strong><\/pre>\n<h1>\u30c4\u30a4\u30fc\u30c8\u3092\u6295\u7a3f\u3059\u308b<\/h1>\n<p>\u3067\u306f\u3001\u3053\u3053\u304b\u3089\u306f\u5b9f\u969b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u5165\u308a\u307e\u3059\u304c\u3001\u5185\u5bb9\u304c\u5c11\u3057\u8907\u96d1\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u307e\u305a\u306f<code>Bit.ly<\/code>\u3067\u4ee5\u4e0b\uff12\u3064\u306e\u90e8\u5206\u306b\u5206\u3051\u3066\u3054\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u77ed\u7e2eURL\u3092\u4f5c\u308b\u90e8\u5206<\/li>\n<li>\u30c4\u30a4\u30fc\u30c8\u6295\u7a3f\u3059\u308b\u90e8\u5206<\/li>\n<\/ul>\n<p>\u305d\u3057\u3066\u3001\u6700\u5f8c\u306b\u3053\u306e\uff12\u3064\u3092\u7d44\u307f\u5408\u308f\u305b\u305f\u5b8c\u5168\u7248\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002\uff08\u5e74\u9f62\u304c\u30d0\u30ec\u307e\u3059\u304c\u30ad\u30f3\u8089\u30de\u30f3\u306e\u30de\u30c3\u30b9\u30eb\u30b9\u30d1\u30fc\u30af\u3068\u540c\u3058\u767a\u60f3\u3067\u3059\ud83d\ude09\uff09<\/p>\n<h2>Bit.ly\u3067\u77ed\u7e2eURL\u3092\u3064\u304f\u308b<\/h2>\n<p>\u3067\u306f\u3001\u306f\u3058\u3081\u306b<code>Node.js<\/code>\u304b\u3089<code>Bit.ly<\/code>\u306e<code>API<\/code>\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u77ed\u7e2eURL\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u3068\u3044\u3063\u3066\u3082\u3001\u5148\u307b\u3069\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u8907\u96d1\u306a\u4f5c\u696d\u3092\u307b\u3068\u3093\u3069\u3084\u3063\u3066\u304f\u308c\u308b\u306e\u3067\u3068\u3066\u3082\u30b7\u30f3\u30d7\u30eb\u306b\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><strong>const BitlyAPI = require('node-bitlyapi');\nconst Bitly = new BitlyAPI();\n\nconst BITLY_ACCESS_TOKEN = '\uff08Bit.ly\u3067\u53d6\u5f97\u3057\u305f\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\uff09';\nconst bitly = Bitly.setAccessToken(BITLY_ACCESS_TOKEN);\n\nconst url = 'https:\/\/example.com\/';<\/strong> \/\/ \u77ed\u7e2e\u3055\u305b\u305f\u3044URL<strong>\nconst params = { longUrl: url };\nbitly.shorten(params, (error, result) =&gt; {\n\n  const results = JSON.parse(result);\n\n  if(results.status_code === 200) {\n\n    const bitlyUrl = results.data.url;<\/strong>  \/\/ \u77ed\u7e2eURL<strong>\n\n  }\n\n});<\/strong><\/pre>\n<p>\u3053\u306e\u4e2d\u306e<code>bitlyUrl<\/code>\u306e\u4e2d\u306b\u4f5c\u6210\u3055\u308c\u305f\u77ed\u7e2eURL\u304c\u683c\u7d0d\u3055\u308c\u3001\u3082\u3057\u3053\u308c\u304c\u30af\u30ea\u30c3\u30af\u3055\u308c\u308b\u3068\u5f8c\u307b\u3069<code>Bit.ly<\/code>\u3067\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b<code>results<\/code>\u306e\u5185\u5bb9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u3082\u306e\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>{\n    status_code: 200,\n    status_txt: 'OK',\n    data: {\n        url: 'http:\/\/bit.ly\/********',\n        hash: '********',\n        global_hash: '********',\n        long_url: 'https:\/\/example.com\/',\n        new_hash: 0\n    }\n}<\/pre>\n<h2>Twitter\u306b\u6295\u7a3f\u3059\u308b<\/h2>\n<p>\u7d9a\u3044\u3066<code>Twitter<\/code>\u306b\u30c4\u30a4\u30fc\u30c8\u6295\u7a3f\u3059\u308b\u90e8\u5206\u3067\u3059\u3002<br \/>\n\u3053\u3061\u3089\u3082\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u307b\u307c\u5168\u3066\u3084\u3063\u3066\u304f\u308c\u308b\u306e\u3067\u3001\u697d\u306b\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><strong>const Twitter = require('twitter');\n\nconst TWITTER_CONSUMER_KEY = '\uff08\u30b3\u30f3\u30b7\u30e5\u30fc\u30de\u30fc\u30fb\u30ad\u30fc\uff09';\nconst TWITTER_CONSUMER_SECRET = '\uff08\u30b3\u30f3\u30b7\u30e5\u30fc\u30de\u30fc\u30fb\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u30fb\u30ad\u30fc\uff09';\nconst TWITTER_ACCESS_TOKEN = '\uff08\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\uff09';\nconst TWITTER_ACCESS_TOKEN_SECRET = '\uff08\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u30fb\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\uff09';\n\nconst twitter = new Twitter({\n  consumer_key: TWITTER_CONSUMER_KEY,\n  consumer_secret: TWITTER_CONSUMER_SECRET,\n  access_token_key: TWITTER_ACCESS_TOKEN,\n  access_token_secret: TWITTER_ACCESS_TOKEN_SECRET\n});\n\nconst postContent = '\uff08\u30c4\u30a4\u30fc\u30c8\u3059\u308b\u5185\u5bb9\uff09';\nconst params = { status: postContent };\ntwitter.post('statuses\/update', params,  (error, tweet, response) =&gt; {\n\n  if(error) {\n\n    <\/strong>\/\/ \u3082\u3057\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u3089\u3053\u3053\u3067\u30e1\u30fc\u30eb\u306a\u3069\u3067\u901a\u77e5\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<strong>\n\n  } else {\n\n    <\/strong>\/\/ \u6210\u529f\u3057\u305f\u5834\u5408<strong>\n\n  }\n\n});<\/strong><\/pre>\n<h2>\u77ed\u7e2eURL\u3092\u52a0\u3048\u305f\u30c4\u30a4\u30fc\u30c8\u3092\u6295\u7a3f\u3059\u308b\uff08\u5b8c\u5168\u7248\uff09<\/h2>\n<p>\u3067\u306f\u3001\u3053\u3053\u307e\u3067\u3067\u3084\u3063\u3066\u304d\u305f<code>Bit.ly<\/code>\u306e\u77ed\u7e2eURL\u4f5c\u6210\u3068<code>Twitter<\/code>\u6295\u7a3f\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u5b8c\u5168\u7248\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u30b3\u30d4\u30da\u3057\u3066\u4f7f\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\ud83d\ude09<\/p>\n<pre><strong>const Twitter = require('twitter');\nconst BitlyAPI = require('node-bitlyapi');\n\n<\/strong>\/\/ \u5b9a\u6570<strong>\nconst TWITTER_CONSUMER_KEY = '\uff08Twitter\u306e\u30b3\u30f3\u30b7\u30e5\u30fc\u30de\u30fc\u30fb\u30ad\u30fc\uff09';\nconst TWITTER_CONSUMER_SECRET = '\uff08Twitter\u306e\u30b3\u30f3\u30b7\u30e5\u30fc\u30de\u30fc\u30fb\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u30fb\u30ad\u30fc\uff09';\nconst TWITTER_ACCESS_TOKEN = '\uff08Twitter\u306e\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\uff09';\nconst TWITTER_ACCESS_TOKEN_SECRET = '\uff08Twitter\u306e\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u30fb\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\uff09';\nconst BITLY_ACCESS_TOKEN = '\uff08Bit.ly\u3067\u53d6\u5f97\u3057\u305f\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\uff09';\n\n<\/strong>\/\/ \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9<strong>\nconst twitter = new Twitter({\n  consumer_key: TWITTER_CONSUMER_KEY,\n  consumer_secret: TWITTER_CONSUMER_SECRET,\n  access_token_key: TWITTER_ACCESS_TOKEN,\n  access_token_secret: TWITTER_ACCESS_TOKEN_SECRET\n});\nconst Bitly = new BitlyAPI();\nconst bitly = Bitly.setAccessToken(BITLY_ACCESS_TOKEN);\n\nconst url = 'https:\/\/example.com\/'; \/\/ \u77ed\u7e2e\u3059\u308bURL\nconst params = { longUrl: url };\nbitly.shorten(params, (error, result) =&gt; {  \/\/ \u77ed\u7e2eURL\u3092\u4f5c\u6210\n\n  const results = JSON.parse(result);\n\n  if(results.status_code === 200) { \/\/ \u77ed\u7e2eURL\u4f5c\u6210\u30fb\u6210\u529f\uff01\n\n    const bitlyUrl = results.data.url;\n    const postContent = '\uff08\u30c4\u30a4\u30fc\u30c8\u306e\u5185\u5bb9\uff09'+ bitlyUrl;\n    const params = { status: postContent };\n    twitter.post('statuses\/update', params,  (error, tweet, response) =&gt; {\n\n      if(error) {\n\n        \/\/ \u30c4\u30a4\u30fc\u30c8\u5931\u6557\n\n      } else {\n\n        \/\/ \u30c4\u30a4\u30fc\u30c8\u6210\u529f\n\n      }\n\n    });\n\n  } else {\n\n    \/\/ \u77ed\u7e2eURL\u4f5c\u6210\u30fb\u5931\u6557...\n\n  }\n\n});<\/strong><\/pre>\n<h1>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b<\/h1>\n<p>\u4eca\u56de\u5b9f\u969b\u306b\u958b\u767a\u3057\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u4ee5\u4e0b\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u203b\u305f\u3060\u3057\u3001<code>Twitter<\/code>\u3068<code>Bit.ly<\/code>\u306e\u30c8\u30fc\u30af\u30f3\u306a\u3069\u306f\u3054\u81ea\u8eab\u3067\u6e96\u5099\u3057\u3066\u3044\u305f\u3060\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/blog.capilano-fw.com?download=5840&amp;tmstv=1777537631\" rel=\"nofollow\" id=\"download-link-5840\" data-redirect=\"false\" >\n\tNode.js\u3067Twitter\u306b\u6295\u7a3f\u3059\u308b<\/a>\n\n<h1>\u3061\u306a\u307f\u306b<\/h1>\n<p>\u4eca\u56de\u7d39\u4ecb\u3057\u305f\u30b3\u30fc\u30c9\u306f\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u304b\u3089\u3067\u3082\u30c4\u30a4\u30fc\u30c8\u6295\u7a3f\u304c\u3067\u304d\u307e\u3059\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u3066\u672c\u756a\u74b0\u5883\u3060\u3051\u30c4\u30a4\u30fc\u30c8\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304f\u3053\u3068\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>if(process.env.NODE_ENV === 'production') {\n<\/strong>\n  twitter.post('statuses\/update', params,  (error, tweet, response) =&gt; {\n\n    \/\/ \u3053\u3053\u3067\u4f55\u304b\n\n  });\n\n} else {\n\n  console.log('\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u304b\u3089\u306f\u30c4\u30a4\u30fc\u30c8\u6295\u7a3f\u3067\u304d\u307e\u305b\u3093\u3002');\n}<\/pre>\n<p>\u306a\u304a\u3001\u74b0\u5883\u5909\u6570\u306f<code>dotenv<\/code>\u3092\u4f7f\u3046\u3068\u697d\u306b\u8a2d\u5b9a\u3067\u304d\u307e\u3059\u3002<br \/>\n\u8a73\u3057\u304f\u306f\u300c<a href=\"https:\/\/blog.capilano-fw.com\/?p=5546#dotenv\" target=\"_blank\" rel=\"noopener noreferrer\">Node.js\u3067.env\u3092\u4f7f\u3046\u65b9\u6cd5<\/a>\u300d\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Node.js<\/code>\u3067\u77ed\u7e2eURL\u3092\u3064\u304f\u308a\u3001\u30c4\u30a4\u30fc\u30c8\u6295\u7a3f\u3092\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u4f7f\u3048\u3070\u3001\u4ee5\u524d<code>Laravel<\/code>\u7248\u3067\u3082\u7d39\u4ecb\u3057\u305f\u3088\u3046\u306b\u4f55\u304b\u30b5\u30a4\u30c8\u306b\u30a2\u30af\u30b7\u30e7\u30f3\u304c\u3042\u3063\u305f\u969b\u306b\u81ea\u52d5\u7684\u306b\u30c4\u30a4\u30fc\u30c8\u3059\u308b\u306a\u3069\u306e\u6a5f\u80fd\u3092\u3064\u304f\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u30b5\u30a4\u30c8\u3067\u3082\u4f7f\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<span style=\"font-size: 1rem;\">\u3067\u306f\u3067\u306f\u301c\uff01<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4445 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2.png\" alt=\"\" width=\"370\" height=\"310\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2-300x251.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001Node.js\u306e\u9ad8\u901f\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u304a\u6c17\u306b\u5165\u308a\u306b\u306a\u3063\u3066\u304d\u305f\u4eca\u65e5\u3053\u306e\u9803\u3067\u3059\u3002 \u3068\u306f\u3044\u3048\u3001\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306eExpress\u306f\u30df\u30cb\u30de\u30eb\u306a\u8a2d\u8a08\u306a\u306e\u3067\u3001\u3082\u3063\u3068Lara &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=5839\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Node.js\u3067Twitter\u306b\u6295\u7a3f\u3059\u308b\uff08Bit.ly\u3067\u77ed\u7e2eURL\u3082\u3064\u304f\u308a\u307e\u3059\uff09&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":5856,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[203],"tags":[192],"class_list":["post-5839","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js","tag-twitter"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5839"}],"version-history":[{"count":7,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5839\/revisions"}],"predecessor-version":[{"id":5854,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/5839\/revisions\/5854"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/5856"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}