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

fatimah #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

91 changes: 91 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Twatt</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="main.js"></script>
</head>
<body>
<nav class='navbar fixed-top navbar-expand-lg navbar-dark bg-dark'>
<a class="navbar-brand" href="#">Twatt</a>
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Profile</a>
</li>

</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</nav>
<div class='container mt-5 pt-5 mx-10 w-75'>
<div class="container-fluid mx-10 w-75">
<div class="col-sm-10">
<textarea id='status' class="form-control" placeholder="What's Happening?"></textarea>
<button type="button" class="btn btn-outline-info mt-2 float-right status" onclick="update()">Tweet</button>
</div>
</div>
<div class="container-fluid pt-5">
<div id="timeline"></div>
</div>
</div>

<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script>
$.ajax({
url: 'http://localhost:3000/home',
type: 'GET',
success: function(resp) {
let tweet = JSON.parse(resp)
tweet.forEach(element => {
// $('.card-title').append(`<h5>${element.entities.user_mentions[0].screen_name}</h5>`)
$('#timeline').append(`
<div class="row">
<div class='col-sm'>
<h6>${element.user.screen_name}<h6>
<p class="font-weight-normal">${element.text}<p>
</div>
</div>`)
// console.log(element)
});
},
error: function() {

}
});

function update() {
$.ajax({
url: 'http://localhost:3000/home',
type: 'POST',
data: {
status: $('#status').val()
},
dataType: 'JSON',
success: function() {
// console.log('success')
window.location.href = '/'
$('#status').val('')
}
})
}

// $('.status').click(function() {

// })

</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# twatt
oauth twitter
27 changes: 27 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const express = require('express')
const bodyParser = require('body-parser')
const home = require('./routes/home')
const profile = require('./routes/profile')
const search = require('./routes/search')
const cors = require('cors')
require('dotenv').config()
const app = express()
const PORT = 3000

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(cors())

app.use('/home', home)
app.use('/profile', profile)
app.use('/search', search)
// app.get('/', (req, res) => {
// res.status(201).json({
// message: 'Connected!'
// })
// })

// Server
app.listen(PORT, () => {
console.log(`Connected! on port ${PORT}`)
})
57 changes: 57 additions & 0 deletions server/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const OAuth = require('oauth')
const twatt = new OAuth.OAuth(
'https://api.twitter.com/oauth/request_token',
'https://api.twitter.com/oauth/access_token',
'NV1fa3P25cEb1HYuNdvR5WAEP',
'nlQMWyqpmMuaRJxjfFrmJcejDDuaTrxlDMcEPIRETMhiipnB53',
'1.0A',
null,
'HMAC-SHA1'
);

module.exports = {
home (req, res) {
twatt.get(
'https://api.twitter.com/1.1/statuses/home_timeline.json',
'90120636-IIh21DpksJqJdKyPQzXwOqisJjaRqIrj4fauYomOq', //test user token
'Hkx0b3q40ZstDnQ4QIdK6XfUf6bQJ0bUzNjuXPJ9UnMiK', //test user secret
function (e, data){
if (e) console.error(e);
res.send(data)
});
},

update (req, res) {
twatt.post(
'https://api.twitter.com/1.1/statuses/update.json?',
'90120636-IIh21DpksJqJdKyPQzXwOqisJjaRqIrj4fauYomOq', //test user token
'Hkx0b3q40ZstDnQ4QIdK6XfUf6bQJ0bUzNjuXPJ9UnMiK', //test user secret
{status: req.body.status},
function (e, data){
if (e) console.error(e);
res.send(data)
});
},

profile (req, res) {
twatt.get(
'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=cimacim&count=10',
process.env.ACCESSTOKEN, //test user token
process.env.TOKENSECRET, //test user secret
function (e, data){
if (e) console.error(e);
res.send(data)
});
},

search (req, res) {
twatt.get(
`https://api.twitter.com/1.1/search/tweets.json?q=${req.params.q}&result_type=mixed&count=4`,
process.env.ACCESSTOKEN, //test user token
process.env.TOKENSECRET, //test user secret
function (e, data){
if (e) console.error(e);
res.send(data)
});
}
}
Loading