Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
These are four contents.
Sample Code
_Twitter_oauth requires Python 2.x superior to 2.5.
These modules are required.
If you use python 2.5, you also need
On Linux.
If you use Python 2.x superior to Python 2.6, skip install simplejson
_ and go to install twitter_oauth
_
If you use python2.5, you should install simplejson first.
Download simplejson from http://pypi.python.org/pypi/simplejson/
_
.. _http://pypi.python.org/pypi/simplejson/
: http://pypi.python.org/pypi/simplejson/
Then, change the directory which contains simplejson file, and
::
$ tar vxzf simplejson-2.1.1.tar.gz $ cd simplejson-2.1.1 $ sudo python setup.py install
From PyPI:
::
$ sudo easy_install twitter_oauth
First, you shold have two keys, 'consumer key', 'consumer secret'.
If you don't have 'consumer key' and 'consumer secret', you cat get these keys to register your application to Twitter. You cat register your application at next URL.
http://twitter.com/apps
_
.. _http://twitter.com/apps
: http://twitter.com/apps
Then, you shold get two keys, 'oauth_token', and 'oauth_token_secret'
To get these keys, you use GetOauth class in this module.
::
>>> import twitter_oauth
>>> # write your key and secret
>>> consumer_key = '***'
>>> consumer_secret = '***'
>>> get_oauth_obj = twitter_oauth.GetOauth(consumer_key, consumer_secret)
Then, you get 'oauth_token' and 'oauth_token_secret' by using get_oauth method. This method returns a dictionary that contain 'consumer key', 'consumer secret', 'oauth_token' and 'oauth_token_secret'
::
>>> get_oauth_obj.get_oauth()
Request Token:
- oauth_token = ***
- oauth_token_secret = ***
Go to the following link in your browser
http://twitter.com/oauth/authorize?oauth_token=***
What is the PIN? ***
Access Token:
- oauth_token = ***
- oauth_token_secret = ***
You may now access protected resources using the access token above
Now, you can use twitter_oauth.Api class. To use this class, you can post update, or get friends timeline, etc...
Next example is how to use twitter_oauth.Api class
::
>>> # import twitter_oauth module
>>> import twitter_oauth
>>> # write yoru consumer_key, consumer_secret,
>>> # oauth_token, oauth_token_secret
>>> consumer_key = '***'
>>> consumer_secret = '***'
>>> oauth_token = '***'
>>> oauth_token_secret = '***'
>>> # Then, create Api instance
>>> api = twitter_oauth.Api(consumer_key, consumer_secret,
>>> oauth_token, oauth_token_secret)
Use get_friends_timeline method. You can get friends timeline to use this method.
::
>>> friends_timeline = api.get_friends_timeline()
>>> print [stauts.text for status in friends_timeline]
Use get_user_timeline method.
You can get user timeline to use this method.
>>> user_timeline = api.get_user_timeline()
>>> print [stauts.text for status in user_timeline]
Use get_replies method.
You can get replies to use this method.
>>> replies = api.get_replies()
>>> print [stauts.text for status in replies]
Use post_update method You can post message to Twitter.
CAUTION : post_update method shold take a unicode. Especially, you can post a Japanese text.
::
>>> api.post_update(tweet=u'Hello, Twitter')
Use get_list_status method.
::
>>> # write username and list name
>>> api.get_list_status(user='username', list_id='listname')
>>> print [status.text for status in api.get_list_status(user="username", list_id="listname")]
Use search method
If you want to show tweets including 'keyword',
::
>>> search_obj = api.search(q='keyword')
>>> print [tweet_info.text for tweet_info in search_obj.results]
If you want to show tweets including 'keyword' and 'anotherkeyword',
::
>>> search_obj = api.search(q='keyword anotherkeyword')
>>> print [tweet_info.text for tweet_info in search_obj.results]
If you want to show tweets including 'keyword' or 'anotherkeyword',
::
>>> search_obj = api.search(q='keyword OR anotherkeyword')
>>> print [tweet_info.text for tweet_info in search_obj.results]
If you want to show timeline from 'user',
::
>>> search_obj = api.search(q='from:user')
>>> print [tweet_info.text for tweet_info in search_obj.results]
If you want to show tweets to 'user', then
::
>>> search_obj = api.search(q='to:user')
>>> print [tweet_info.text for tweet_info in search_obj.results]
If you want to show tweets from 'user' to 'another', then
::
>>> search_obj = api.search(q='from:user to:another')
>>> print [tweet_info.text for tweet_info in search_obj.results]
If you want to search tag,
::
>>> search_obj = api.search(q='#twitter')
>>> print [tweet_info.text for tweet_info in search_obj.results]
To know more information about a search method, see the next link.
http://dev.twitter.com/doc/get/search
_
.. _http://dev.twitter.com/doc/get/search
: http://dev.twitter.com/doc/get/search
You can use next methods
status
timeline
list
friendship
user
search
::
#! /usr/bin/env python
# coding:utf-8
import twitter_oauth
# write your oauth token and oauth token secret
consumer_key = '***'
consumer_secret = '***'
# create GetOauth instance
get_oauth_obj = twitter_oauth.GetOauth(consumer_key, consumer_secret)
# get oauth_token and oauth token secret
key_dict = get_oauth_obj.get_oauth()
# create Api instance
api = twitter_oauth.Api(consumer_key, consumer_secret, key_dict['oauth_token'], key_dict['oauth_token_secret'])
## timeline method
# get friends timeline
print [status.text for status in api.get_friends_timeline()]
# get user timeline
print [status.text for status in api.get_user_timeline()]
# get replies
print [status.text for status in api.get_replies()]
## status method
# post update
api.post_update(tweet=u'Hello, Twitter')
# show status and destroy status
status = api.get_user_timeline()[0]
print api.show_status(id=status.id).text
api.destroy_status(id=status.id)
## friendship method
api.create_friendship(id='twitter')
api.destroy_friendship(id='twitter')
## user method
print api.show_user(id='twitter').screen_name
print [user.screen_name for user in api.search_user(q='twitter')]
## search method
print [tweet_info.text for tweet_info in api.search(q='#twitter').results]
FAQs
A Python module for Twitter API and OAuth
We found that twitter_oauth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.