Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 4 #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
release 3
  • Loading branch information
FTeddy committed Mar 7, 2018
commit 4452894b59bd8b5e0f2546cae7afe475bf03647c
81 changes: 74 additions & 7 deletions controllers/oauth.js
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ const OAuth = require('oauth')
var oauth = new OAuth.OAuth(
'https://api.twitter.com/oauth/request_token',
'https://api.twitter.com/oauth/access_token',
`tyDWzfKPvPZzAqYyztmlCXEqk`,
`MqN2N8BMfFH2p7XAtJAr9Mf2ee29dmGjQkRgM5u0KyC8KEjBnA`,
`${process.env.APPCONSKEY}`,
`${process.env.APPCONSSECRET}`,
'1.0A',
null,
'HMAC-SHA1'
@@ -15,15 +15,15 @@ module.exports = {
searchHacktivTweet(req, res){
oauth.get(
'https://api.twitter.com/1.1/search/tweets.json?q=hacktiv8',
`105831931-cuvXQkW8RF9Fb8bsXCVByxOltMwahthsocHcRaj4`, //test user token
`36gnZF9f8mwE3eEqvvwxx4BDk5YUjQqfkTVusqOma95uP`, //test user secret
`${process.env.APPTOKEN}`, //test user token
`${process.env.APPSECRET}`, //test user secret
function (e, data, response){
if (e) {
// console.log(data);
let error = JSON.parse(e)
// let error = JSON.parse(e)
res.status(500).json({
message: 'error retreiving api',
err: error
err: e
})
} else {
let dataJSON = JSON.parse(data)
@@ -35,7 +35,74 @@ module.exports = {

});

}
},

ownTimeline(req, res){
oauth.get(
'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=Werkbau&count=2',
`${process.env.APPTOKEN}`, //test user token
`${process.env.APPSECRET}`, //test user secret
function (e, data, response){
if (e) {
res.status(500).json({
message: 'error retreiving api',
err: e
})
} else {
let dataJSON = JSON.parse(data)
res.status(200).json({
message: 'Twitter api call successful',
data: dataJSON
})
}

});
},

searchTwitter(req, res){
let query = req.query.q
oauth.get(
`https://api.twitter.com//1.1/search/tweets.json?q=`+ query,
`${process.env.APPTOKEN}`, //test user token
`${process.env.APPSECRET}`, //test user secret
function (e, data, response){
if (e) {
res.status(500).json({
message: 'error retreiving api',
err: e
})
} else {
let dataJSON = JSON.parse(data)
res.status(200).json({
message: 'Twitter api call successful',
data: dataJSON
})
}

});
},

postTweet(req, res){
let status = req.query.status
oauth.get(
`https://api.twitter.com/1.1/statuses/update.json?status=`+ status,
`${process.env.APPTOKEN}`, //test user token
`${process.env.APPSECRET}`, //test user secret
function (e, data, response){
if (e) {
res.status(500).json({
message: 'error retreiving api',
err: e
})
} else {
let dataJSON = JSON.parse(data)
res.status(200).json({
message: 'Twitter api call successful',
data: dataJSON
})
}

});
}

}
3 changes: 3 additions & 0 deletions routes/oauth.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,9 @@ const oauthController = require('../controllers/oauth.js')
// console.log(oauthController);
/* GET users listing. */
router.get('/', oauthController.searchHacktivTweet);
router.get('/timeline', oauthController.ownTimeline);
router.post('/search', oauthController.searchTwitter);
router.post('/post', oauthController.postTweet);


module.exports = router;