Skip to content

Commit

Permalink
Adding get_access_token helper script
Browse files Browse the repository at this point in the history
Adding test_settings support for local settings, and putting it in .gitignore
  • Loading branch information
Mike Krieger committed Feb 2, 2011
1 parent f84f047 commit 42b4927
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.pyc
.DS_Store
*.swp
test_settings.py

28 changes: 28 additions & 0 deletions get_access_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from instagram.client import InstagramAPI

try:
from test_settings import *

InstagramAPI.host = test_host
InstagramAPI.base_path = test_base_path
InstagramAPI.access_token_field = "access_token"
InstagramAPI.authorize_url = test_authorize_url
InstagramAPI.access_token_url = test_access_token_url
InstagramAPI.protocol = test_protocol
except Exception:
pass

client_id = raw_input("Client ID: ").strip()
client_secret = raw_input("Client Secret: ").strip()
redirect_uri = raw_input("Redirect URI: ").strip()

api = InstagramAPI(client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)
redirect_uri = api.get_authorize_login_url()

print "Visit this page and authorize access in your browser:\n", redirect_uri

code = raw_input("Paste in code in query string after redirect: ").strip()

access_token = api.exchange_code_for_access_token(code)
print "access token:\n", access_token

27 changes: 19 additions & 8 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import sys
import time
import getpass
import unittest
from instagram import *

client_id = "124a2ff750454d2ba4f70ddc0fc691d2"
client_secret = "22d0c7184ece41bebd0de13788a31a31"
access_token = "124a2ff.fb8bfc19ff7a47008d55e0edc74ad7aa"
redirect_uri = "http://mikeyktest.com"
try:
from test_settings import *
except Exception:
print "Must have a test_settings.py file with settings defined"
sys.exit(1)


class TestInstagramAPI(InstagramAPI):
host = test_host
base_path = test_base_path
access_token_field = "access_token"
authorize_url = test_authorize_url
access_token_url = test_access_token_url
protocol = test_protocol


class InstagramAuthTests(unittest.TestCase):
def setUp(self):
self.unauthenticated_api = InstagramAPI(client_id=client_id, redirect_uri=redirect_uri, client_secret=client_secret)
self.unauthenticated_api = TestInstagramAPI(client_id=client_id, redirect_uri=redirect_uri, client_secret=client_secret)

def test_authorize_login_url(self):
redirect_uri = self.unauthenticated_api.get_authorize_login_url()
Expand All @@ -31,15 +43,14 @@ def test_xauth_exchange(self):
return
password = getpass.getpass("Enter password for XAuth (blank to skip): ").strip()
access_token = self.unauthenticated_api.exchange_xauth_login_for_access_token(username, password)
print 'authorized with access token ', access_token
assert access_token


class InstagramAPITests(unittest.TestCase):

def setUp(self):
self.client_only_api = InstagramAPI(client_id=client_id)
self.api = InstagramAPI(access_token=access_token)
self.client_only_api = TestInstagramAPI(client_id=client_id)
self.api = TestInstagramAPI(access_token=access_token)

def test_popular_media(self):
self.api.popular_media(count=10)
Expand Down

0 comments on commit 42b4927

Please sign in to comment.