forked from ideoforms/python-twitter-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter-friendship.py
executable file
·43 lines (34 loc) · 1.8 KB
/
twitter-friendship.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python
#-----------------------------------------------------------------------
# twitter-friendship
# - outputs details of the relationship between two users.
#-----------------------------------------------------------------------
from twitter import *
#-----------------------------------------------------------------------
# load our API credentials
#-----------------------------------------------------------------------
config = {}
execfile("config.py", config)
#-----------------------------------------------------------------------
# create twitter API object
#-----------------------------------------------------------------------
twitter = Twitter(
auth = OAuth(config["access_key"], config["access_secret"], config["consumer_key"], config["consumer_secret"]))
#-----------------------------------------------------------------------
# the usernames whose relationship we want to examine
#-----------------------------------------------------------------------
source = "ideoforms"
target = "lewisrichard"
#-----------------------------------------------------------------------
# perform the API query
# twitter API docs: https://dev.twitter.com/rest/reference/get/friendships/show
#-----------------------------------------------------------------------
result = twitter.friendships.show(source_screen_name = source,
target_screen_name = target)
#-----------------------------------------------------------------------
# extract the relevant properties
#-----------------------------------------------------------------------
following = result["relationship"]["target"]["following"]
follows = result["relationship"]["target"]["followed_by"]
print "%s following %s: %s" % (source, target, follows)
print "%s following %s: %s" % (target, source, following)