Last active
September 4, 2019 22:59
-
-
Save alexjlockwood/6797443 to your computer and use it in GitHub Desktop.
Authenticating with Piazza's Internal REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
from cookielib import CookieJar | |
cj = CookieJar() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
# login to Piazza. | |
login_url = 'https://piazza.com/logic/api?method=user.login' | |
login_data = '{"method":"user.login","params":{"email":"[email protected]","pass":"fakePassword"}}' | |
# if the user/password match, the server respond will contain a session cookie | |
# that you can use to authenticate future requests. | |
login_resp = opener.open(login_url, login_data) | |
print login_resp.read() | |
# get the content of some random Piazza post on the 15-214 Piazza site. | |
content_url = 'https://piazza.com/logic/api?method=get.content' | |
content_data = '{"method":"content.get","params":{"cid":"hm8b1yx8v234m2","nid":"hkqe3rh2nlz35d"}}' | |
content_resp = opener.open(content_url, content_data) | |
print content_resp.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment