Skip to content

Commit

Permalink
Add script_auth_friend_list.py example.
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Feb 14, 2016
1 parent 04e91cb commit b30052c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/script_auth_friend_list.py
@@ -0,0 +1,36 @@
#!/usr/bin/env python

"""script_auth_friend_list.py outputs the authenticated user's list of friends.
This program demonstrates the use of ``prawcore.ScriptAuthorizer``, which
enables those listed as a developer of the application to authenticate using
their username and password.
"""
import os
import prawcore
import sys


def main():
"""main is the program's entry point when directly executed."""
authenticator = prawcore.Authenticator(
os.environ['PRAWCORE_CLIENT_ID'],
os.environ['PRAWCORE_CLIENT_SECRET'])
authorizer = prawcore.ScriptAuthorizer(authenticator,
os.environ['PRAWCORE_USERNAME'],
os.environ['PRAWCORE_PASSWORD'])
authorizer.refresh()

url = 'https://oauth.reddit.com/api/v1/me/friends'
with prawcore.session(authorizer) as session:
data = session.request('GET', url)

for friend in data['data']['children']:
print(friend['name'])

return 0


if __name__ == '__main__':
sys.exit(main())

0 comments on commit b30052c

Please sign in to comment.