Fix samples so that they catch AccessTokenRefreshError.

This commit is contained in:
Joe Gregorio
2011-05-16 21:58:52 -07:00
parent c242eb4077
commit 7d791210d7
6 changed files with 140 additions and 99 deletions

View File

@@ -54,9 +54,20 @@ for filename in glob.glob('samples/src/*.py'):
for line in config.split('\n'):
key, value = line[1:].split(':', 1)
variables[key.strip()] = value.strip()
lines = content.split('\n')
outlines = []
for l in lines:
if l:
outlines.append(' ' + l)
else:
outlines.append('')
content = '\n'.join(outlines)
variables['description'] = textwrap.fill(variables['description'])
variables['content'] = content
variables['name'] = os.path.basename(filename).split('.', 1)[0]
f = open(os.path.join('samples', variables['name'], variables['name'] + '.py'), 'w')
f.write(template.substitute(variables))
f.close()

View File

@@ -43,6 +43,7 @@ import sys
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
@@ -97,6 +98,8 @@ def main(argv):
service = build("buzz", "v1", http=http)
try:
activities = service.activities()
# Retrieve the first two activities
@@ -135,6 +138,9 @@ def main(argv):
pprint.pprint(comment)
except AccessTokenRefreshError:
print ("The credentials have been revoked or expired, please re-run"
"the application to re-authorize")
if __name__ == '__main__':
main(sys.argv)

View File

@@ -42,6 +42,7 @@ import sys
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
@@ -96,6 +97,8 @@ def main(argv):
service = build("moderator", "v1", http=http)
try:
# Create a new Moderator series.
series_body = {
"description": "Share and rank tips for eating healthy and cheap!",
@@ -139,6 +142,9 @@ def main(argv):
except AccessTokenRefreshError:
print ("The credentials have been revoked or expired, please re-run"
"the application to re-authorize")
if __name__ == '__main__':
main(sys.argv)

View File

@@ -43,6 +43,7 @@ import sys
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
@@ -97,6 +98,8 @@ def main(argv):
service = build("prediction", "v1.2", http=http)
try:
# Name of Google Storage bucket/object that contains the training data
OBJECT_NAME = "apiclient-prediction-sample/prediction_models/languages"
@@ -125,6 +128,9 @@ def main(argv):
pprint.pprint(prediction)
except AccessTokenRefreshError:
print ("The credentials have been revoked or expired, please re-run"
"the application to re-authorize")
if __name__ == '__main__':
main(sys.argv)

View File

@@ -42,6 +42,7 @@ import sys
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
@@ -96,8 +97,13 @@ def main(argv):
service = build("$name", "$version", http=http)
try:
$content
except AccessTokenRefreshError:
print ("The credentials have been revoked or expired, please re-run"
"the application to re-authorize")
if __name__ == '__main__':
main(sys.argv)

View File

@@ -43,6 +43,7 @@ import sys
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
@@ -97,6 +98,8 @@ def main(argv):
service = build("urlshortener", "v1", http=http)
try:
url = service.url()
# Create a shortened URL by inserting the URL into the url collection.
@@ -111,6 +114,9 @@ def main(argv):
pprint.pprint(resp)
except AccessTokenRefreshError:
print ("The credentials have been revoked or expired, please re-run"
"the application to re-authorize")
if __name__ == '__main__':
main(sys.argv)