Expanded Moderator sample. Also made JsonBody more robust, allowing the external 'data' wrapper to be passed in from the caller or added, depending on whether it is present or not. Also handle adding user-agents better, by concatenating them.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"data": {
|
||||
"moderator": {
|
||||
"v1": {
|
||||
"baseUrl": "https://www.googleapis.com/",
|
||||
"baseUrl": "https://www.googleapis.com/",
|
||||
"auth": {
|
||||
"request": {
|
||||
"url": "https://www.google.com/accounts/OAuthGetRequestToken",
|
||||
|
||||
@@ -94,7 +94,10 @@ class JsonModel(object):
|
||||
if body_value is None:
|
||||
return (headers, path_params, query, None)
|
||||
else:
|
||||
model = {'data': body_value}
|
||||
if len(body_value) == 1 and 'data' in body_value:
|
||||
model = body_value
|
||||
else:
|
||||
model = {'data': body_value}
|
||||
headers['content-type'] = 'application/json'
|
||||
return (headers, path_params, query, simplejson.dumps(model))
|
||||
|
||||
|
||||
@@ -130,8 +130,11 @@ class OAuthCredentials(Credentials):
|
||||
if headers == None:
|
||||
headers = {}
|
||||
headers.update(req.to_header())
|
||||
if 'user-agent' not in headers:
|
||||
headers['user-agent'] = self.user_agent
|
||||
if 'user-agent' in headers:
|
||||
headers['user-agent'] += ' '
|
||||
else:
|
||||
headers['user-agent'] = ''
|
||||
headers['user-agent'] += self.user_agent
|
||||
return request_orig(uri, method, body, headers,
|
||||
redirections, connection_type)
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ from apiclient.discovery import build
|
||||
import httplib2
|
||||
import pickle
|
||||
|
||||
# Uncomment to get detailed logging
|
||||
# httplib2.debuglevel = 4
|
||||
|
||||
def main():
|
||||
f = open("moderator.dat", "r")
|
||||
@@ -27,7 +29,47 @@ def main():
|
||||
http = credentials.authorize(http)
|
||||
|
||||
p = build("moderator", "v1", http=http)
|
||||
print p.submissions().list(seriesId="7035", topicId="64").execute()
|
||||
|
||||
series_body = {
|
||||
"description": "Share and rank tips for eating healthily on the cheaps!",
|
||||
"name": "Eating Healthy & Cheap",
|
||||
"videoSubmissionAllowed": False
|
||||
}
|
||||
series = p.series().insert(body=series_body).execute()
|
||||
print "Created a new series"
|
||||
|
||||
topic_body = {
|
||||
"data": {
|
||||
"description": "Share your ideas on eating healthy!",
|
||||
"name": "Ideas",
|
||||
"presenter": "liz"
|
||||
}
|
||||
}
|
||||
topic = p.topics().insert(seriesId=series['id']['seriesId'], body=topic_body).execute()
|
||||
print "Created a new topic"
|
||||
|
||||
submission_body = {
|
||||
"data": {
|
||||
"attachmentUrl": "http://www.youtube.com/watch?v=1a1wyc5Xxpg",
|
||||
"attribution": {
|
||||
"displayName": "Bashan",
|
||||
"location": "Bainbridge Island, WA"
|
||||
},
|
||||
"text": "Charlie Ayers @ Google"
|
||||
}
|
||||
}
|
||||
submission = p.submissions().insert(seriesId=topic['id']['seriesId'],
|
||||
topicId=topic['id']['topicId'], body=submission_body).execute()
|
||||
print "Inserted a new submisson on the topic"
|
||||
|
||||
vote_body = {
|
||||
"data": {
|
||||
"vote": "PLUS"
|
||||
}
|
||||
}
|
||||
p.votes().insert(seriesId=topic['id']['seriesId'], submissionId=submission['id']['submissionId'], body=vote_body)
|
||||
print "Voted on the submission"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -35,6 +35,7 @@ flow = FlowThreeLegged(moderator_discovery,
|
||||
user_agent='google-api-client-python-mdrtr-cmdline/1.0',
|
||||
domain='anonymous',
|
||||
scope='https://www.googleapis.com/auth/moderator',
|
||||
#scope='tag:google.com,2010:auth/moderator',
|
||||
xoauth_displayname='Google API Client Example App')
|
||||
|
||||
authorize_url = flow.step1_get_authorize_url()
|
||||
|
||||
Reference in New Issue
Block a user