本文整理汇总了Python中test_oauth_client.TestOAuthClient类的典型用法代码示例。如果您正苦于以下问题:Python TestOAuthClient类的具体用法?Python TestOAuthClient怎么用?Python TestOAuthClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestOAuthClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: profileScrape
def profileScrape():
global POINTS
resource_url = "/api/v1/user"
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
start = time.time()
response = client.access_resource(resource_url, ACCESS_TOKEN)
mongoclient = MongoClient()
db = mongoclient.flexkhan
start = time.time()
parsed_json = json.loads(response)
length = len(parsed_json)
profile = db.profile
find = profile.find({})
dbCount = profile.find({}).count()-1
end = time.time()
if dbCount == 0:
POINTS = find[0]["points"]
if parsed_json["points"] == POINTS:
print "Match"
else:
print "No Match"
result = db.profile.insert_one(parsed_json)
POINTS = parsed_json["points"]
示例2: get_api_resource
def get_api_resource():
global result, ticker
resource_url = "/api/v1/user/exercises/progress_changes"
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
start = time.time()
response = client.access_resource(resource_url, ACCESS_TOKEN)
end = time.time()
print type(response)
print "\n"
parsed_json = json.loads(response)
print type(parsed_json)
length = len(parsed_json)
mclient = MongoClient()
db = mclient.flexkhan
progress = db.progress
# result = db.progress.insert_one(parsed_json[0])
result = progress.find()
size = result.count()
ticker = 0
while ticker < size:
date = datetime.strptime(result[ticker]['date'], "%Y-%m-%dT%H:%M:%SZ")
aware = pytz.timezone('US/Mountain').localize(date)
utc_dt = aware.astimezone(pytz.utc)
print utc_dt.strftime("%Y:%m:%d %I:%M:%S")
ticker += 1
print "\nTime: %ss\n" % (end - start)
示例3: progressUpdate
def progressUpdate():
resource_url = "/api/v1/user/exercises/progress_changes"
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
response = client.access_resource(resource_url, ACCESS_TOKEN)
mongoclient = MongoClient()
db = mongoclient.flexkhan
counter = 0
while counter == 0:
start = time.time()
parsed_json = json.loads(response)
freshSize = len(parsed_json)
progress = db.progress
find = progress.find({})
currentDBCount = progress.find({}).count()
if currentDBCount != freshSize:
diff = freshSize - currentDBCount
diffcounter = diff
i = 0
while i < diffcounter:
marker = freshSize-diff+i
print parsed_json[marker]
print "\n"
print marker
result = db.progress.insert_one(parsed_json[marker])
i += 1
else:
print("No diff")
# print "\nTime: %ss\n" % (end - start)
counter = 1
示例4: get_request_token
def get_request_token():
server = create_callback_server()
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
client.start_fetch_request_token('http://127.0.0.1:%d/' % server.server_address[1])
server.handle_request()
# REQUEST_TOKEN has now been set
server.server_close()
示例5: get_api_resource
def get_api_resource():
resource_url = raw_input("Resource relative url (/api/v1/playlists): ") or "/api/v1/playlists"
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
start = time.time()
response = client.access_resource(resource_url, ACCESS_TOKEN)
end = time.time()
print "\n"
print response
print "\nTime: %ss\n" % (end - start)
示例6: get_api_resource
def get_api_resource():
resource_url = (raw_input("Resource relative url (/api/v1/playlists): ") or
"/api/v1/playlists")
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
response = client.access_resource(resource_url, ACCESS_TOKEN)
print "\n"
print response
print "\n"
示例7: get_api_resource
def get_api_resource(resource_url = '/api/v1/user/exercises/scientific_notation'):
#resource_url = '/api/v1/user/exercises/scientific_notation' #JS# raw_input("Resource relative url (/api/v1/playlists): ") \
#or "/api/v1/playlists"
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
start = time.time()
response = client.access_resource(resource_url, ACCESS_TOKEN)
end = time.time()
return response, start, end
示例8: get_request_token
def get_request_token():
global REQUEST_TOKEN
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
client.start_fetch_request_token()
print "After logging in and authorizing, input token key and secret..."
request_token_key = raw_input("request token: ")
request_token_secret = raw_input("request token secret: ")
REQUEST_TOKEN = OAuthToken(request_token_key, request_token_secret)
示例9: get_api_resource
def get_api_resource(self, resourceUrl):
# Example URLs
# /api/v1/user/exercises/[email protected]
# /api/v1/[email protected]
# /api/v1/exercises
client = TestOAuthClient(self.SERVER_URL, self.CONSUMER_KEY, self.CONSUMER_SECRET)
start = time.time()
response = client.access_resource(resourceUrl, self.ACCESS_TOKEN)
end = time.time()
# print "\nTime: %ss\n" % (end - start)
return response
示例10: get_access_token_from_user
def get_access_token_from_user():
client = TestOAuthClient(consts.SERVER_URL, consts.CONSUMER_KEY, consts.CONSUMER_SECRET)
client.start_fetch_request_token()
print "After logging in and authorizing, input token key and secret..."
request_token_key = raw_input("request token: ")
request_token_secret = raw_input("request token secret: ")
request_token = OAuthToken(request_token_key, request_token_secret)
if not request_token:
raise IOError("Did not get request token.")
print "Fetching access token..."
access_token = client.fetch_access_token(request_token)
if not access_token:
raise IOError("Did not get access token.")
return access_token
示例11: api_call
def api_call(target_version, target_api_url, debug=False, authenticate=True):
"""
Generic API call function, that will try to use an authenticated request if available,
otherwise will fall back to non-authenticated request.
"""
# TODO : Use requests for both kinds of authentication.
# usage : api_call("v1", "/badges")
resource_url = "/api/" + target_version + target_api_url
try:
if authenticate and REQUEST_TOKEN and ACCESS_TOKEN:
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
response = client.access_resource(resource_url, ACCESS_TOKEN)
else:
response = requests.get(SERVER_URL + resource_url).content
json_object = json.loads(response)
except Exception as e:
print e
return {}
if(debug):
print json_object
return json_object
示例12: authenticate
def authenticate():
"""
Adapted from https://github.com/Khan/khan-api/blob/master/examples/test_client/test.py
First pass at browser based OAuth authentication.
"""
# TODO: Allow PIN access for non-browser enabled devices.
server = create_callback_server()
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
client.start_fetch_request_token(
'http://127.0.0.1:%d/' % server.server_address[1])
server.handle_request()
server.server_close()
global ACCESS_TOKEN
ACCESS_TOKEN = client.fetch_access_token(REQUEST_TOKEN)
示例13: authenticate
def authenticate(self):
"""
Adapted from https://github.com/Khan/khan-api/blob/master/examples/test_client/test.py
First pass at browser based OAuth authentication.
"""
# TODO: Allow PIN access for non-browser enabled devices.
if CONSUMER_KEY and CONSUMER_SECRET:
server = create_callback_server(self)
client = TestOAuthClient(
self.SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
client.start_fetch_request_token(
'http://127.0.0.1:%d/' % server.server_address[1])
server.handle_request()
server.server_close()
self.ACCESS_TOKEN = client.fetch_access_token(self.REQUEST_TOKEN)
else:
print "Consumer key and secret not set in secrets.py - authenticated access to API unavailable."
示例14: progressScrape
def progressScrape():
resource_url = "/api/v1/user/exercises/progress_changes"
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
response = client.access_resource(resource_url, ACCESS_TOKEN)
mongoclient = MongoClient()
db = mongoclient.flexkhan
counter = 0
while counter == 0:
parsed_json = json.loads(response)
size = len(parsed_json)
progress = db.progress
i = 0
while i < size:
result = db.progress.insert_one(parsed_json[i])
print("Check!")
i += 1
end = time.time()
# print "\nTime: %ss\n" % (end - start)
counter = 1
示例15: get_access_token
def get_access_token():
global ACCESS_TOKEN
client = TestOAuthClient(SERVER_URL, CONSUMER_KEY, CONSUMER_SECRET)
ACCESS_TOKEN = client.fetch_access_token(REQUEST_TOKEN)