Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Python sample code #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
writer.close();
// Here, we're just copying the response returned by the API to the page served to the browser.
response.setCharacterEncoding("UTF-8");
response.setContentType("text/javascript");
response.setContentType("application/json");
IOUtils.copy(connection.getInputStream(), response.getOutputStream());
}

Expand Down
27 changes: 11 additions & 16 deletions python/rpxtokenurl.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# This code sample shows how to make the auth_info API call using Python.

import urllib
import urllib2

# json is native in python 2.6, but must be installed for previous versions
import json
import requests

# Step 1) Extract the token from your environment. If you are using app engine,
# you'd do something like:
Expand All @@ -24,23 +20,25 @@

# Step 2) Now that we have the token, we need to make the api call to auth_info.
# auth_info expects an HTTP Post with the following paramters:
api_params = {

engage_api_params = {
'token': token,
'apiKey': 'REPLACE_WITH_YOUR_RPX_API_KEY',
'format': 'json',
'format': 'json'
}

engage_api_url = 'https://rpxnow.com/api/v2/auth_info'

# make the api call
http_response = urllib2.urlopen('https://rpxnow.com/api/v2/auth_info',
urllib.urlencode(api_params))

# read the json response
auth_info_json = http_response.read()
api_response = requests.get(engage_api_url, params=engage_api_params)

# Step 3) process the json response
auth_info = json.loads(auth_info_json)

auth_info = api_response.json()

# Step 4) use the response to sign the user in

if auth_info['stat'] == 'ok':
profile = auth_info['profile']

Expand All @@ -60,7 +58,4 @@
sign_in_user(identifier, name, email, profile_pic_url)

else:
print 'An error occured: ' + auth_info['err']['msg']



print 'An error occured: ' + auth_info['err']['msg']