BoyCook / TwitterJSClient

Twitter client written in JavaScript packaged as a node module
GNU General Public License v2.0
562 stars 176 forks source link

how to return data from search #69

Closed SaeedSoltoon closed 6 years ago

SaeedSoltoon commented 6 years ago

hi, how to return data from search api ?

in success function i just return data except console.log but nothing returned to the browser.

console.log working properly.

this is my code.

var express = require('express'); var router = express.Router();

var error = function (err, response, body) { console.log('ERROR [%s]', err); }; var success = function (data) { // console.log('Data [%s]', data); return data; };

var config = { "consumerKey": "xxx", "consumerSecret": "xxx", "accessToken": "xxx", "accessTokenSecret": "xxx", "callBackUrl": "xxx" };

var Twitter = require('twitter-node-client').Twitter;

router.get('/recent/', function(req, res, next) { var twitter = new Twitter(config); var mytweets = twitter.getSearch({'q':'#messi','count': 3}, error, success); // res.send(mytweets); res.json(mytweets); });

module.exports = router;

thank you.

SaeedSoltoon commented 6 years ago

i have to write sth like this.

router.get('/recent/', function (req, res) {

var twitter = new Twitter(config);

var data = twitter.getSearch({'q':'#iran','count': 3}, function(error, response, body){ res.status(404).send({ "error" : "tag Not Found" }); }, function(data){ res.send({ result : { "tweets" : JSON.parse(data) } }); });

});