Created
February 27, 2012 20:56
-
-
Save StuMx/1926974 to your computer and use it in GitHub Desktop.
Twitter stream using javascript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* You have to include oauth.js and sha1.js from here http://oauth.googlecode.com/svn/code/javascript/ | |
* / | |
var url = "https://userstream.twitter.com/2/user.json"; | |
var accessor = { | |
token: "", | |
tokenSecret: "", | |
consumerKey : "", | |
consumerSecret: "" | |
}; | |
var message = { | |
action: url, | |
method: "GET", | |
parameters: {} | |
}; | |
OAuth.completeRequest(message, accessor); | |
OAuth.SignatureMethod.sign(message, accessor); | |
url = url + '?' + OAuth.formEncode(message.parameters); | |
var messageLen = 0; | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', url, true); | |
xhr.onreadystatechange = function() { | |
if(xhr.readyState == 2 && xhr.status == 200) { | |
// Connection is ok | |
} else if(xhr.readyState == 3){ | |
//Receiving stream | |
if (messageLen < xhr.responseText.length){ | |
alert(messageLen +"-"+ xhr.responseText.length +":"+xhr.responseText.substring(messageLen,xhr.responseText.length)); | |
} | |
messageLen = xhr.responseText.length; | |
}else if(xhr.readyState == 4) {} | |
// Connection completed | |
}; | |
xhr.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Disculpa, encontré tu código buscando por todo Internet, hice lo que tu especificas, alli y agregue la dos librerías mas que tu recomiendas. Pero me aparecen estos errores
Quisiera tambien saber como se envian los paremetros aqui
**parameters: {}**
Ojala me pudieras ayudar, gracias.