<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Python%3A_twitterstream.py</id>
	<title>Python: twitterstream.py - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Python%3A_twitterstream.py"/>
	<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=Python:_twitterstream.py&amp;action=history"/>
	<updated>2026-04-27T07:07:52Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://lms.onnocenter.or.id/wiki/index.php?title=Python:_twitterstream.py&amp;diff=46535&amp;oldid=prev</id>
		<title>Onnowpurbo: Created page with &quot; import oauth2 as oauth  import urllib2 as urllib    # See assignment1.html instructions or README for how to get these credentials    api_key = &quot;&lt;Enter api key&gt;&quot;  api_secret...&quot;</title>
		<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=Python:_twitterstream.py&amp;diff=46535&amp;oldid=prev"/>
		<updated>2017-01-20T23:18:55Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; import oauth2 as oauth  import urllib2 as urllib    # See assignment1.html instructions or README for how to get these credentials    api_key = &amp;quot;&amp;lt;Enter api key&amp;gt;&amp;quot;  api_secret...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt; import oauth2 as oauth&lt;br /&gt;
 import urllib2 as urllib&lt;br /&gt;
 &lt;br /&gt;
 # See assignment1.html instructions or README for how to get these credentials&lt;br /&gt;
 &lt;br /&gt;
 api_key = &amp;quot;&amp;lt;Enter api key&amp;gt;&amp;quot;&lt;br /&gt;
 api_secret = &amp;quot;&amp;lt;Enter api secret&amp;gt;&amp;quot;&lt;br /&gt;
 access_token_key = &amp;quot;&amp;lt;Enter your access token key here&amp;gt;&amp;quot;&lt;br /&gt;
 access_token_secret = &amp;quot;&amp;lt;Enter your access token secret here&amp;gt;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 _debug = 0&lt;br /&gt;
 &lt;br /&gt;
 oauth_token    = oauth.Token(key=access_token_key, secret=access_token_secret)&lt;br /&gt;
 oauth_consumer = oauth.Consumer(key=api_key, secret=api_secret)&lt;br /&gt;
 &lt;br /&gt;
 signature_method_hmac_sha1 = oauth.SignatureMethod_HMAC_SHA1()&lt;br /&gt;
 &lt;br /&gt;
 http_method = &amp;quot;GET&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 http_handler  = urllib.HTTPHandler(debuglevel=_debug)&lt;br /&gt;
 https_handler = urllib.HTTPSHandler(debuglevel=_debug)&lt;br /&gt;
 &lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
 Construct, sign, and open a twitter request&lt;br /&gt;
 using the hard-coded credentials above.&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
 def twitterreq(url, method, parameters):&lt;br /&gt;
   req = oauth.Request.from_consumer_and_token(oauth_consumer,&lt;br /&gt;
                                              token=oauth_token,&lt;br /&gt;
                                              http_method=http_method,&lt;br /&gt;
                                              http_url=url, &lt;br /&gt;
                                              parameters=parameters) &lt;br /&gt;
 &lt;br /&gt;
   req.sign_request(signature_method_hmac_sha1, oauth_consumer, oauth_token)&lt;br /&gt;
 &lt;br /&gt;
   headers = req.to_header()&lt;br /&gt;
 &lt;br /&gt;
   if http_method == &amp;quot;POST&amp;quot;:&lt;br /&gt;
     encoded_post_data = req.to_postdata()&lt;br /&gt;
   else:&lt;br /&gt;
     encoded_post_data = None&lt;br /&gt;
     url = req.to_url() &lt;br /&gt;
 &lt;br /&gt;
   opener = urllib.OpenerDirector()&lt;br /&gt;
   opener.add_handler(http_handler)&lt;br /&gt;
   opener.add_handler(https_handler)&lt;br /&gt;
 &lt;br /&gt;
   response = opener.open(url, encoded_post_data)&lt;br /&gt;
 &lt;br /&gt;
   return response&lt;br /&gt;
 &lt;br /&gt;
 def fetchsamples():&lt;br /&gt;
   url = &amp;quot;https://stream.twitter.com/1/statuses/sample.json&amp;quot;&lt;br /&gt;
   parameters = []&lt;br /&gt;
   response = twitterreq(url, &amp;quot;GET&amp;quot;, parameters)&lt;br /&gt;
   for line in response:&lt;br /&gt;
     print line.strip()&lt;br /&gt;
 &lt;br /&gt;
 if __name__ == &amp;#039;__main__&amp;#039;:&lt;br /&gt;
   fetchsamples()&lt;/div&gt;</summary>
		<author><name>Onnowpurbo</name></author>
	</entry>
</feed>