JavaScript
1const functions = require("firebase-functions"); 2 3// // Create and Deploy Your First Cloud Functions 4// // https://firebase.google.com/docs/functions/write-firebase-functions 5// 6// exports.helloWorld = functions.https.onRequest((request, response) => { 7// functions.logger.info("Hello logs!", {structuredData: true}); 8// response.send("テスト!"); 9// }); 10 11exports.helloOnCall = functions.https.onRequest((req, res) => { 12 const request = require("request"); 13 14 const URL = "https://api.twitter.com/1.1/users/show.json"; 15 16 request.get({ 17 uri: URL, 18 headers: { 19 "Content-type": "application/json", 20 // eslint-disable-next-line quote-props 21 Authorization: 22 // eslint-disable-next-line max-len 23 "Bearer XXXXXXXXXXXXXXXXXXXXXX", 24 }, 25 qs: { 26 screen_name: "AbeShinzo", 27 }, 28 json: true, 29 }, 30 function(error, req, data) { 31 if (!error) { 32 console.log(data.name); 33 } else { 34 console.log(error); 35 } 36 } 37 ); 38 39 // const resJson = res.getBody("utf-8"); 40 41 // const obj = JSON.parse(resJson); // オブジェクトをJSONとして文字列として出力 42 // // parse=JSON形式の文字列を文字列として置き換える 43 44 // const returnRes = { 45 // name: obj.data.name, 46 // }; 47 // return returnRes; 48}); 49
これで curl "URL"でアカウント名が表示されるようにしたいが、エラーが出てしまいます。
公式のドキュメントをみながら実装しました。
わからないこと
・onCallとonRequestの使い分け
・現状firebase emulators:start --only functionsでローカルで起動させるとエラーが表示される→解決方法がわかっていない(おそらくコードの書き方が間違っている)
エラーと思われる文章
Emulator │ Host:Port │ View in Emulator UI │
├───────────┼────────────────┼─────────────────────────────────┤
│ Functions │ localhost:5001 │ http://localhost:4000/functions │
└───────────┴────────────────┴─────────────────────────────────┘
Emulator Hub running at localhost:4400
Other reserved ports: 4500
Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
何卒よろしくお願いいたします
あなたの回答
tips
プレビュー