Cleanup of samples including adding flags to control logging.
diff --git a/apiclient/discovery.py b/apiclient/discovery.py
index cc31967..aabbade 100644
--- a/apiclient/discovery.py
+++ b/apiclient/discovery.py
@@ -114,6 +114,7 @@
   try:
     service = simplejson.loads(content)
   except ValueError, e:
+    logging.error('Failed to parse as JSON: ' + content)
     raise InvalidJsonError()
 
   fn = os.path.join(os.path.dirname(__file__), 'contrib',
diff --git a/apiclient/model.py b/apiclient/model.py
index 4ca91f4..1e5b862 100644
--- a/apiclient/model.py
+++ b/apiclient/model.py
@@ -22,7 +22,10 @@
 FLAGS = gflags.FLAGS
 
 gflags.DEFINE_boolean('dump_request_response', False,
-                     'Dump all http server requests and responses.')
+                     'Dump all http server requests and responses. '
+                     'Must use apiclient.model.LoggingJsonModel as '
+                     'the model.'
+                     )
 
 
 def _abstract():
diff --git a/oauth2client/client.py b/oauth2client/client.py
index 69724f3..1a3937b 100644
--- a/oauth2client/client.py
+++ b/oauth2client/client.py
@@ -192,6 +192,7 @@
         'user-agent': self.user_agent,
         'content-type': 'application/x-www-form-urlencoded'
     }
+    logging.info("Refresing access_token")
     resp, content = http_request(
         self.token_uri, method='POST', body=body, headers=headers)
     if resp.status == 200:
@@ -218,6 +219,8 @@
           self._invalid = True
           if self.store is not None:
             self.store(self)
+          else:
+            logging.warning("Unable to store refreshed credentials, no Storage provided.")
       except:
         pass
       raise AccessTokenRefreshError(error_msg)
diff --git a/samples/api-python-client-doc/gflags.py b/samples/api-python-client-doc/gflags.py
new file mode 120000
index 0000000..5a2ff94
--- /dev/null
+++ b/samples/api-python-client-doc/gflags.py
@@ -0,0 +1 @@
+../../gflags.py
\ No newline at end of file
diff --git a/samples/api-python-client-doc/gflags_validators.py b/samples/api-python-client-doc/gflags_validators.py
new file mode 120000
index 0000000..25d8ce8
--- /dev/null
+++ b/samples/api-python-client-doc/gflags_validators.py
@@ -0,0 +1 @@
+../../gflags_validators.py
\ No newline at end of file
diff --git a/samples/django_sample/buzz/views.py b/samples/django_sample/buzz/views.py
index d8d37c2..0205c4f 100644
--- a/samples/django_sample/buzz/views.py
+++ b/samples/django_sample/buzz/views.py
@@ -50,10 +50,6 @@
 def auth_return(request):
     try:
       f = Flow.objects.get(id=request.user)
-      print f
-      print f.flow
-      print dir(f.flow)
-      print type(f.flow)
       credential = f.flow.step2_exchange(request.REQUEST)
       c = Credential(id=request.user, credential=credential)
       c.save()
diff --git a/samples/new_project_template/gflags.py b/samples/new_project_template/gflags.py
new file mode 120000
index 0000000..5a2ff94
--- /dev/null
+++ b/samples/new_project_template/gflags.py
@@ -0,0 +1 @@
+../../gflags.py
\ No newline at end of file
diff --git a/samples/new_project_template/gflags_validators.py b/samples/new_project_template/gflags_validators.py
new file mode 120000
index 0000000..25d8ce8
--- /dev/null
+++ b/samples/new_project_template/gflags_validators.py
@@ -0,0 +1 @@
+../../gflags_validators.py
\ No newline at end of file
diff --git a/samples/oauth2/appengine/gflags.py b/samples/oauth2/appengine/gflags.py
new file mode 120000
index 0000000..157177e
--- /dev/null
+++ b/samples/oauth2/appengine/gflags.py
@@ -0,0 +1 @@
+../../../gflags.py
\ No newline at end of file
diff --git a/samples/oauth2/appengine/gflags_validators.py b/samples/oauth2/appengine/gflags_validators.py
new file mode 120000
index 0000000..9d359e0
--- /dev/null
+++ b/samples/oauth2/appengine/gflags_validators.py
@@ -0,0 +1 @@
+../../../gflags_validators.py
\ No newline at end of file
diff --git a/samples/oauth2/buzz/buzz.py b/samples/oauth2/buzz/buzz.py
index 86ceaf9..74ee3a4 100644
--- a/samples/oauth2/buzz/buzz.py
+++ b/samples/oauth2/buzz/buzz.py
@@ -11,36 +11,47 @@
 
 __author__ = 'jcgregorio@google.com (Joe Gregorio)'
 
+import gflags
 import httplib2
-import pickle
+import logging
 import pprint
+import sys
 
 from apiclient.discovery import build
 from oauth2client.file import Storage
 from oauth2client.client import OAuth2WebServerFlow
 from oauth2client.tools import run
 
-# Uncomment the next line to get very detailed logging
-#httplib2.debuglevel = 4
+FLAGS = gflags.FLAGS
+FLOW = OAuth2WebServerFlow(
+    client_id='433807057907.apps.googleusercontent.com',
+    client_secret='jigtZpMApkRxncxikFpR+SFg',
+    scope='https://www.googleapis.com/auth/buzz',
+    user_agent='buzz-cmdline-sample/1.0')
+
+gflags.DEFINE_enum('logging_level', 'ERROR',
+    ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
+    'Set the level of logging detail.')
 
 
-def main():
+def main(argv):
+  try:
+    argv = FLAGS(argv)
+  except gflags.FlagsError, e:
+    print '%s\\nUsage: %s ARGS\\n%s' % (e, argv[0], FLAGS)
+    sys.exit(1)
+
+  logging.getLogger().setLevel(getattr(logging, FLAGS.logging_level))
+
   storage = Storage('buzz.dat')
   credentials = storage.get()
   if credentials is None or credentials.invalid == True:
-    flow = OAuth2WebServerFlow(
-        client_id='433807057907.apps.googleusercontent.com',
-        client_secret='jigtZpMApkRxncxikFpR+SFg',
-        scope='https://www.googleapis.com/auth/buzz',
-        user_agent='buzz-cmdline-sample/1.0',
-        domain='anonymous',
-        xoauth_displayname='Buzz Client Example App'
-        )
-    credentials = run(flow, storage)
+    credentials = run(FLOW, storage)
 
   http = httplib2.Http()
   http = credentials.authorize(http)
 
+  # Build the Buzz service
   service = build("buzz", "v1", http=http,
             developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
   activities = service.activities()
@@ -57,13 +68,11 @@
 
   # Add a new activity
   new_activity_body = {
-      "data": {
-          'title': 'Testing insert',
-          'object': {
-              'content':
-                u'Just a short note to show that insert is working. ☄',
-              'type': 'note'}
-          }
+      'title': 'Testing insert',
+      'object': {
+        'content':
+        u'Just a short note to show that insert is working. ☄',
+        'type': 'note'}
       }
   activity = activities.insert(userId='@me', body=new_activity_body).execute()
   print "Added a new activity"
@@ -73,9 +82,7 @@
 
   # Add a comment to that activity
   comment_body = {
-      "data": {
-          "content": "This is a comment"
-          }
+      "content": "This is a comment"
       }
   item = activitylist['items'][0]
   comment = service.comments().insert(
@@ -85,4 +92,4 @@
   pprint.pprint(comment)
 
 if __name__ == '__main__':
-  main()
+  main(sys.argv)
diff --git a/samples/oauth2/django_sample/buzz/views.py b/samples/oauth2/django_sample/buzz/views.py
index c4ec4d0..c942aaf 100644
--- a/samples/oauth2/django_sample/buzz/views.py
+++ b/samples/oauth2/django_sample/buzz/views.py
@@ -15,7 +15,7 @@
 from django.http import HttpResponseRedirect
 from django.shortcuts import render_to_response
 
-STEP2_URI = 'http://gregorio2.cnc.corp.google.com:8000/auth_return'
+STEP2_URI = 'http://localhost:8000/auth_return'
 
 
 @login_required
@@ -52,10 +52,6 @@
 def auth_return(request):
     try:
       f = FlowModel.objects.get(id=request.user)
-      print f
-      print f.flow
-      print dir(f.flow)
-      print type(f.flow)
       credential = f.flow.step2_exchange(request.REQUEST)
       storage = Storage(CredentialsModel, 'id', request.user, 'credential')
       storage.put(credential)
diff --git a/samples/oauth2/moderator/moderator.py b/samples/oauth2/moderator/moderator.py
index 1578abd..c75c962 100644
--- a/samples/oauth2/moderator/moderator.py
+++ b/samples/oauth2/moderator/moderator.py
@@ -12,6 +12,7 @@
 
 import gflags
 import httplib2
+import logging
 import sys
 
 from apiclient.discovery import build
@@ -20,6 +21,16 @@
 from oauth2client.tools import run
 
 FLAGS = gflags.FLAGS
+FLOW = OAuth2WebServerFlow(
+    client_id='433807057907.apps.googleusercontent.com',
+    client_secret='jigtZpMApkRxncxikFpR+SFg',
+    scope='https://www.googleapis.com/auth/moderator',
+    user_agent='moderator-cmdline-sample/1.0')
+
+gflags.DEFINE_enum('logging_level', 'ERROR',
+    ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
+    'Set the level of logging detail.')
+
 
 def main(argv):
   try:
@@ -28,17 +39,13 @@
     print '%s\\nUsage: %s ARGS\\n%s' % (e, argv[0], FLAGS)
     sys.exit(1)
 
+  logging.getLogger().setLevel(getattr(logging, FLAGS.logging_level))
+
   storage = Storage('moderator.dat')
   credentials = storage.get()
 
   if credentials is None or credentials.invalid == True:
-    flow = OAuth2WebServerFlow(
-        client_id='433807057907.apps.googleusercontent.com',
-        client_secret='jigtZpMApkRxncxikFpR+SFg',
-        scope='https://www.googleapis.com/auth/moderator',
-        user_agent='moderator-cmdline-sample/1.0')
-
-    credentials = run(flow, storage)
+    credentials = run(FLOW, storage)
 
   http = httplib2.Http(cache=".cache")
   http = credentials.authorize(http)
diff --git a/samples/oauth2/urlshortener/main.py b/samples/oauth2/urlshortener/main.py
index 32a60df..62945c5 100644
--- a/samples/oauth2/urlshortener/main.py
+++ b/samples/oauth2/urlshortener/main.py
@@ -10,8 +10,11 @@
 
 __author__ = 'jcgregorio@google.com (Joe Gregorio)'
 
+import gflags
 import httplib2
+import logging
 import pprint
+import sys
 
 from apiclient.discovery import build
 from oauth2client.file import Storage
@@ -19,22 +22,31 @@
 from oauth2client.client import AccessTokenCredentials
 from oauth2client.tools import run
 
-# Uncomment to get detailed logging
-#httplib2.debuglevel = 4
+FLAGS = gflags.FLAGS
+FLOW = OAuth2WebServerFlow(
+    client_id='433807057907.apps.googleusercontent.com',
+    client_secret='jigtZpMApkRxncxikFpR+SFg',
+    scope='https://www.googleapis.com/auth/urlshortener',
+    user_agent='urlshortener-cmdline-sample/1.0')
+
+gflags.DEFINE_enum('logging_level', 'ERROR',
+    ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
+    'Set the level of logging detail.')
 
 
-def main():
+def main(argv):
+  try:
+    argv = FLAGS(argv)
+  except gflags.FlagsError, e:
+    print '%s\\nUsage: %s ARGS\\n%s' % (e, argv[0], FLAGS)
+    sys.exit(1)
+
+  logging.getLogger().setLevel(getattr(logging, FLAGS.logging_level))
+
   storage = Storage('urlshortener.dat')
   credentials = storage.get()
-
   if credentials is None or credentials.invalid == True:
-    flow = OAuth2WebServerFlow(
-        client_id='433807057907.apps.googleusercontent.com',
-        client_secret='jigtZpMApkRxncxikFpR+SFg',
-        scope='https://www.googleapis.com/auth/urlshortener',
-        user_agent='urlshortener-cmdline-sample/1.0')
-
-    credentials = run(flow, storage)
+    credentials = run(FLOW, storage)
 
   http = httplib2.Http()
   http = credentials.authorize(http)
@@ -57,4 +69,4 @@
 
 
 if __name__ == '__main__':
-  main()
+  main(sys.argv)