Skip to content

Instantly share code, notes, and snippets.

@StuMx
Created February 27, 2012 20:56
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StuMx/1926974 to your computer and use it in GitHub Desktop.
Save StuMx/1926974 to your computer and use it in GitHub Desktop.
Twitter stream using javascript.
/*
* 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();
@PterPmnta
Copy link

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

**Uncaught TypeError: Cannot set property 'setProperties' of undefined

TypeError: Cannot read property 'completeRequest' of undefined**

Quisiera tambien saber como se envian los paremetros aqui

**parameters: {}**

Ojala me pudieras ayudar, gracias.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment