Updated all samples to use 'service' as the object returned from build()
This commit is contained in:
@@ -239,6 +239,7 @@ def createResource(http, baseUrl, model, requestBuilder,
|
|||||||
methodDesc['parameters']['body'] = {
|
methodDesc['parameters']['body'] = {
|
||||||
'description': 'The request body.',
|
'description': 'The request body.',
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
|
'required': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
argmap = {} # Map from method parameter name to query parameter name
|
argmap = {} # Map from method parameter name to query parameter name
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
from django.db import models
|
import apiclient
|
||||||
|
import base64
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
class OAuthCredentialsField(models.Field):
|
class OAuthCredentialsField(models.Field):
|
||||||
|
|
||||||
|
@@ -53,8 +53,8 @@ class MainHandler(webapp.RequestHandler):
|
|||||||
if c:
|
if c:
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
http = c.credentials.authorize(http)
|
http = c.credentials.authorize(http)
|
||||||
p = build("buzz", "v1", http=http)
|
service = build("buzz", "v1", http=http)
|
||||||
activities = p.activities()
|
activities = service.activities()
|
||||||
activitylist = activities.list(scope='@consumption',
|
activitylist = activities.list(scope='@consumption',
|
||||||
userId='@me').execute()
|
userId='@me').execute()
|
||||||
logging.info(activitylist)
|
logging.info(activitylist)
|
||||||
|
@@ -43,9 +43,9 @@ def main():
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
http = credentials.authorize(http)
|
http = credentials.authorize(http)
|
||||||
|
|
||||||
p = build("buzz", "v1", http=http,
|
service = build("buzz", "v1", http=http,
|
||||||
developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
|
developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
|
||||||
activities = p.activities()
|
activities = service.activities()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Retrieve the first two activities
|
# Retrieve the first two activities
|
||||||
@@ -82,7 +82,7 @@ def main():
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
item = activitylist['items'][0]
|
item = activitylist['items'][0]
|
||||||
comment = p.comments().insert(
|
comment = service.comments().insert(
|
||||||
userId=item['actor']['id'], postId=item['id'], body=comment_body
|
userId=item['actor']['id'], postId=item['id'], body=comment_body
|
||||||
).execute()
|
).execute()
|
||||||
print 'Added a comment to the new activity'
|
print 'Added a comment to the new activity'
|
||||||
|
@@ -19,9 +19,9 @@ import pprint
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
p = build("customsearch", "v1",
|
service = build("customsearch", "v1",
|
||||||
developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
|
developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
|
||||||
res = p.cse().list(
|
res = service.cse().list(
|
||||||
q='lectures',
|
q='lectures',
|
||||||
cx='017576662512468239146:omuauf_lfve',
|
cx='017576662512468239146:omuauf_lfve',
|
||||||
).execute()
|
).execute()
|
||||||
|
@@ -22,9 +22,9 @@ import pprint
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
p = build("diacritize", "v1",
|
service = build("diacritize", "v1",
|
||||||
developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
|
developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
|
||||||
print p.diacritize().corpus().get(
|
print service.diacritize().corpus().get(
|
||||||
lang='ar',
|
lang='ar',
|
||||||
last_letter='false',
|
last_letter='false',
|
||||||
message=u'مثال لتشكيل'
|
message=u'مثال لتشكيل'
|
||||||
|
@@ -20,8 +20,8 @@ def index(request):
|
|||||||
c = Credential.objects.get(id=request.user)
|
c = Credential.objects.get(id=request.user)
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
http = c.credential.authorize(http)
|
http = c.credential.authorize(http)
|
||||||
p = build("buzz", "v1", http=http)
|
service = build("buzz", "v1", http=http)
|
||||||
activities = p.activities()
|
activities = service.activities()
|
||||||
activitylist = activities.list(scope='@consumption',
|
activitylist = activities.list(scope='@consumption',
|
||||||
userId='@me').execute()
|
userId='@me').execute()
|
||||||
logging.info(activitylist)
|
logging.info(activitylist)
|
||||||
@@ -31,8 +31,8 @@ def index(request):
|
|||||||
})
|
})
|
||||||
|
|
||||||
except Credential.DoesNotExist:
|
except Credential.DoesNotExist:
|
||||||
p = build("buzz", "v1")
|
service = build("buzz", "v1")
|
||||||
flow = FlowThreeLegged(p.auth_discovery(),
|
flow = FlowThreeLegged(service.auth_discovery(),
|
||||||
consumer_key='anonymous',
|
consumer_key='anonymous',
|
||||||
consumer_secret='anonymous',
|
consumer_secret='anonymous',
|
||||||
user_agent='google-api-client-python-buzz-django/1.0',
|
user_agent='google-api-client-python-buzz-django/1.0',
|
||||||
|
@@ -51,7 +51,7 @@ def main():
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
http = credentials.authorize(http)
|
http = credentials.authorize(http)
|
||||||
|
|
||||||
p = build("latitude", "v1", http=http)
|
service = build("latitude", "v1", http=http)
|
||||||
|
|
||||||
body = {
|
body = {
|
||||||
"data": {
|
"data": {
|
||||||
@@ -62,7 +62,7 @@ def main():
|
|||||||
"altitude": 35
|
"altitude": 35
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print p.currentLocation().insert(body=body).execute()
|
print service.currentLocation().insert(body=body).execute()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@@ -29,9 +29,9 @@ DISCOVERY_URI = ('http://localhost:3990/discovery/v0.2beta1/describe/'
|
|||||||
def main():
|
def main():
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
|
|
||||||
p = build("buzz", "v1", http=http, discoveryServiceUrl=DISCOVERY_URI)
|
service = build("buzz", "v1", http=http, discoveryServiceUrl=DISCOVERY_URI)
|
||||||
help(p.activities().list)
|
help(service.activities().list)
|
||||||
print p.activities().list(userId='@self', scope='@me', c='foo').uri
|
print service.activities().list(userId='@self', scope='@me', c='foo').uri
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@@ -55,12 +55,12 @@ def main():
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Construct a service from the local documents
|
# Construct a service from the local documents
|
||||||
p = build_from_document(discovery,
|
service = build_from_document(discovery,
|
||||||
base="https://www.googleapis.com/",
|
base="https://www.googleapis.com/",
|
||||||
future=future,
|
future=future,
|
||||||
http=http,
|
http=http,
|
||||||
developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
|
developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
|
||||||
activities = p.activities()
|
activities = service.activities()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Retrieve the first two activities
|
# Retrieve the first two activities
|
||||||
|
@@ -36,7 +36,6 @@ def main():
|
|||||||
user_agent='python-moderator-sample/1.0',
|
user_agent='python-moderator-sample/1.0',
|
||||||
domain='anonymous',
|
domain='anonymous',
|
||||||
scope='https://www.googleapis.com/auth/moderator',
|
scope='https://www.googleapis.com/auth/moderator',
|
||||||
#scope='tag:google.com,2010:auth/moderator',
|
|
||||||
xoauth_displayname='Google API Client Example App')
|
xoauth_displayname='Google API Client Example App')
|
||||||
|
|
||||||
credentials = run(flow, storage)
|
credentials = run(flow, storage)
|
||||||
@@ -44,7 +43,7 @@ def main():
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
http = credentials.authorize(http)
|
http = credentials.authorize(http)
|
||||||
|
|
||||||
p = build('moderator', 'v1', http=http)
|
service = build('moderator', 'v1', http=http)
|
||||||
|
|
||||||
series_body = {
|
series_body = {
|
||||||
'description': 'Share and rank tips for eating healthy and cheap!',
|
'description': 'Share and rank tips for eating healthy and cheap!',
|
||||||
@@ -52,7 +51,7 @@ def main():
|
|||||||
'videoSubmissionAllowed': False
|
'videoSubmissionAllowed': False
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
series = p.series().insert(body=series_body).execute()
|
series = service.series().insert(body=series_body).execute()
|
||||||
print 'Created a new series'
|
print 'Created a new series'
|
||||||
|
|
||||||
topic_body = {
|
topic_body = {
|
||||||
@@ -60,7 +59,7 @@ def main():
|
|||||||
'name': 'Ideas',
|
'name': 'Ideas',
|
||||||
'presenter': 'liz'
|
'presenter': 'liz'
|
||||||
}
|
}
|
||||||
topic = p.topics().insert(seriesId=series['id']['seriesId'],
|
topic = service.topics().insert(seriesId=series['id']['seriesId'],
|
||||||
body=topic_body).execute()
|
body=topic_body).execute()
|
||||||
print 'Created a new topic'
|
print 'Created a new topic'
|
||||||
|
|
||||||
@@ -72,14 +71,14 @@ def main():
|
|||||||
},
|
},
|
||||||
'text': 'Charlie Ayers @ Google'
|
'text': 'Charlie Ayers @ Google'
|
||||||
}
|
}
|
||||||
submission = p.submissions().insert(seriesId=topic['id']['seriesId'],
|
submission = service.submissions().insert(seriesId=topic['id']['seriesId'],
|
||||||
topicId=topic['id']['topicId'], body=submission_body).execute()
|
topicId=topic['id']['topicId'], body=submission_body).execute()
|
||||||
print 'Inserted a new submisson on the topic'
|
print 'Inserted a new submisson on the topic'
|
||||||
|
|
||||||
vote_body = {
|
vote_body = {
|
||||||
'vote': 'PLUS'
|
'vote': 'PLUS'
|
||||||
}
|
}
|
||||||
p.votes().insert(seriesId=topic['id']['seriesId'],
|
service.votes().insert(seriesId=topic['id']['seriesId'],
|
||||||
submissionId=submission['id']['submissionId'],
|
submissionId=submission['id']['submissionId'],
|
||||||
body=vote_body)
|
body=vote_body)
|
||||||
print 'Voted on the submission'
|
print 'Voted on the submission'
|
||||||
|
@@ -67,8 +67,8 @@ class MainHandler(webapp.RequestHandler):
|
|||||||
else:
|
else:
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
http = credentials.authorize(http)
|
http = credentials.authorize(http)
|
||||||
p = build("buzz", "v1", http=http)
|
service = build("buzz", "v1", http=http)
|
||||||
activities = p.activities()
|
activities = service.activities()
|
||||||
activitylist = activities.list(scope='@consumption',
|
activitylist = activities.list(scope='@consumption',
|
||||||
userId='@me').execute()
|
userId='@me').execute()
|
||||||
path = os.path.join(os.path.dirname(__file__), 'welcome.html')
|
path = os.path.join(os.path.dirname(__file__), 'welcome.html')
|
||||||
|
@@ -41,9 +41,9 @@ def main():
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
http = credentials.authorize(http)
|
http = credentials.authorize(http)
|
||||||
|
|
||||||
p = build("buzz", "v1", http=http,
|
service = build("buzz", "v1", http=http,
|
||||||
developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
|
developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
|
||||||
activities = p.activities()
|
activities = service.activities()
|
||||||
|
|
||||||
# Retrieve the first two activities
|
# Retrieve the first two activities
|
||||||
activitylist = activities.list(
|
activitylist = activities.list(
|
||||||
@@ -78,7 +78,7 @@ def main():
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
item = activitylist['items'][0]
|
item = activitylist['items'][0]
|
||||||
comment = p.comments().insert(
|
comment = service.comments().insert(
|
||||||
userId=item['actor']['id'], postId=item['id'], body=comment_body
|
userId=item['actor']['id'], postId=item['id'], body=comment_body
|
||||||
).execute()
|
).execute()
|
||||||
print 'Added a comment to the new activity'
|
print 'Added a comment to the new activity'
|
||||||
|
@@ -37,8 +37,8 @@ def index(request):
|
|||||||
else:
|
else:
|
||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
http = credential.authorize(http)
|
http = credential.authorize(http)
|
||||||
p = build("buzz", "v1", http=http)
|
service = build("buzz", "v1", http=http)
|
||||||
activities = p.activities()
|
activities = service.activities()
|
||||||
activitylist = activities.list(scope='@consumption',
|
activitylist = activities.list(scope='@consumption',
|
||||||
userId='@me').execute()
|
userId='@me').execute()
|
||||||
logging.info(activitylist)
|
logging.info(activitylist)
|
||||||
|
@@ -38,7 +38,7 @@ def main():
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
http = credentials.authorize(http)
|
http = credentials.authorize(http)
|
||||||
|
|
||||||
p = build("latitude", "v1", http=http)
|
service = build("latitude", "v1", http=http)
|
||||||
|
|
||||||
body = {
|
body = {
|
||||||
"data": {
|
"data": {
|
||||||
@@ -50,7 +50,7 @@ def main():
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
print p.currentLocation().insert(body=body).execute()
|
print service.currentLocation().insert(body=body).execute()
|
||||||
except CredentialsInvalidError:
|
except CredentialsInvalidError:
|
||||||
print 'Your credentials are no longer valid.'
|
print 'Your credentials are no longer valid.'
|
||||||
print 'Please re-run this application to re-authorize.'
|
print 'Please re-run this application to re-authorize.'
|
||||||
|
@@ -39,7 +39,7 @@ def main():
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
http = credentials.authorize(http)
|
http = credentials.authorize(http)
|
||||||
|
|
||||||
p = build("moderator", "v1", http=http)
|
service = build("moderator", "v1", http=http)
|
||||||
|
|
||||||
series_body = {
|
series_body = {
|
||||||
"data": {
|
"data": {
|
||||||
@@ -48,7 +48,7 @@ def main():
|
|||||||
"videoSubmissionAllowed": False
|
"videoSubmissionAllowed": False
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
series = p.series().insert(body=series_body).execute()
|
series = service.series().insert(body=series_body).execute()
|
||||||
print "Created a new series"
|
print "Created a new series"
|
||||||
|
|
||||||
topic_body = {
|
topic_body = {
|
||||||
@@ -58,7 +58,7 @@ def main():
|
|||||||
"presenter": "liz"
|
"presenter": "liz"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
topic = p.topics().insert(seriesId=series['id']['seriesId'],
|
topic = service.topics().insert(seriesId=series['id']['seriesId'],
|
||||||
body=topic_body).execute()
|
body=topic_body).execute()
|
||||||
print "Created a new topic"
|
print "Created a new topic"
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ def main():
|
|||||||
"text": "Charlie Ayers @ Google"
|
"text": "Charlie Ayers @ Google"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
submission = p.submissions().insert(seriesId=topic['id']['seriesId'],
|
submission = service.submissions().insert(seriesId=topic['id']['seriesId'],
|
||||||
topicId=topic['id']['topicId'], body=submission_body).execute()
|
topicId=topic['id']['topicId'], body=submission_body).execute()
|
||||||
print "Inserted a new submisson on the topic"
|
print "Inserted a new submisson on the topic"
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ def main():
|
|||||||
"vote": "PLUS"
|
"vote": "PLUS"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.votes().insert(seriesId=topic['id']['seriesId'],
|
service.votes().insert(seriesId=topic['id']['seriesId'],
|
||||||
submissionId=submission['id']['submissionId'],
|
submissionId=submission['id']['submissionId'],
|
||||||
body=vote_body)
|
body=vote_body)
|
||||||
print "Voted on the submission"
|
print "Voted on the submission"
|
||||||
|
@@ -100,7 +100,7 @@ def main():
|
|||||||
http = httplib2.Http()
|
http = httplib2.Http()
|
||||||
http = credentials.authorize(http)
|
http = credentials.authorize(http)
|
||||||
|
|
||||||
p = build("moderator", "v1", http=http)
|
service = build("moderator", "v1", http=http)
|
||||||
|
|
||||||
series_body = {
|
series_body = {
|
||||||
"data": {
|
"data": {
|
||||||
@@ -110,7 +110,7 @@ def main():
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
series = p.series().insert(body=series_body).execute()
|
series = service.series().insert(body=series_body).execute()
|
||||||
print "Created a new series"
|
print "Created a new series"
|
||||||
|
|
||||||
for i in range(NUM_ITEMS):
|
for i in range(NUM_ITEMS):
|
||||||
@@ -121,7 +121,7 @@ def main():
|
|||||||
"presenter": "me"
|
"presenter": "me"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
topic_request = p.topics().insert(seriesId=series['id']['seriesId'],
|
topic_request = service.topics().insert(seriesId=series['id']['seriesId'],
|
||||||
body=topic_body)
|
body=topic_body)
|
||||||
print "Adding request to queue"
|
print "Adding request to queue"
|
||||||
queue.put(topic_request)
|
queue.put(topic_request)
|
||||||
|
@@ -21,9 +21,9 @@ import pprint
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
p = build('translate', 'v2',
|
service = build('translate', 'v2',
|
||||||
developerKey='AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0')
|
developerKey='AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0')
|
||||||
print p.translations().list(
|
print service.translations().list(
|
||||||
source='en',
|
source='en',
|
||||||
target='fr',
|
target='fr',
|
||||||
q=['flower', 'car']
|
q=['flower', 'car']
|
||||||
|
Reference in New Issue
Block a user