Make compatible with oauth2client v2.0.0
The v2.0.0 release moved a few modules to a subpackage of oauth2client
called contrib. Among these was the locked_file module necessary for
credential storage.
Sample code for Django, App Engine and Service Accounts needed updates
as well.
diff --git a/googleapiclient/discovery_cache/file_cache.py b/googleapiclient/discovery_cache/file_cache.py
index ce540f0..8b0301d 100644
--- a/googleapiclient/discovery_cache/file_cache.py
+++ b/googleapiclient/discovery_cache/file_cache.py
@@ -29,7 +29,7 @@
import tempfile
import threading
-from oauth2client.locked_file import LockedFile
+from oauth2client.contrib.locked_file import LockedFile
from . import base
from ..discovery_cache import DISCOVERY_DOC_MAX_AGE
diff --git a/samples/appengine/main.py b/samples/appengine/main.py
index 3d8587b..d2a3223 100644
--- a/samples/appengine/main.py
+++ b/samples/appengine/main.py
@@ -31,8 +31,8 @@
import pickle
from googleapiclient import discovery
-from oauth2client import appengine
from oauth2client import client
+from oauth2client.contrib import appengine
from google.appengine.api import memcache
import webapp2
diff --git a/samples/django_sample/plus/models.py b/samples/django_sample/plus/models.py
index 890b278..6b9f762 100644
--- a/samples/django_sample/plus/models.py
+++ b/samples/django_sample/plus/models.py
@@ -5,8 +5,8 @@
from django.contrib.auth.models import User
from django.db import models
-from oauth2client.django_orm import FlowField
-from oauth2client.django_orm import CredentialsField
+from oauth2client.contrib.django_orm import FlowField
+from oauth2client.contrib.django_orm import CredentialsField
class CredentialsModel(models.Model):
diff --git a/samples/django_sample/plus/views.py b/samples/django_sample/plus/views.py
index 1196cef..0699d96 100644
--- a/samples/django_sample/plus/views.py
+++ b/samples/django_sample/plus/views.py
@@ -13,7 +13,7 @@
from django_sample import settings
from oauth2client import xsrfutil
from oauth2client.client import flow_from_clientsecrets
-from oauth2client.django_orm import Storage
+from oauth2client.contrib.django_orm import Storage
# CLIENT_SECRETS, name of a file containing the OAuth 2.0 information for this
# application, including client_id and client_secret, which are found
diff --git a/samples/service_account/tasks.py b/samples/service_account/tasks.py
index 7de049d..43fc357 100644
--- a/samples/service_account/tasks.py
+++ b/samples/service_account/tasks.py
@@ -34,23 +34,19 @@
import sys
from googleapiclient.discovery import build
-from oauth2client.client import SignedJwtAssertionCredentials
+from oauth2client.service_account import ServiceAccountCredentials
def main(argv):
- # Load the key in PKCS 12 format that you downloaded from the Google API
- # Console when you created your Service account.
- f = file('key.p12', 'rb')
- key = f.read()
- f.close()
+ # Load the json format key that you downloaded from the Google API
+ # Console when you created your service account. For p12 keys, use the
+ # from_p12_keyfile method of ServiceAccountCredentials and specify the
+ # service account email address, p12 keyfile, and scopes.
+ credentials = ServiceAccountCredentials.from_json_keyfile_name(
+ 'service-account-abcdef123456.json',
+ scopes='https://www.googleapis.com/auth/tasks')
- # Create an httplib2.Http object to handle our HTTP requests and authorize it
- # with the Credentials. Note that the first parameter, service_account_name,
- # is the Email address created for the Service account. It must be the email
- # address associated with the key that was created.
- credentials = SignedJwtAssertionCredentials(
- '141491975384@developer.gserviceaccount.com',
- key,
- scope='https://www.googleapis.com/auth/tasks')
+ # Create an httplib2.Http object to handle our HTTP requests and authorize
+ # it with the Credentials.
http = httplib2.Http()
http = credentials.authorize(http)
diff --git a/samples/storage_serviceaccount_appengine/main.py b/samples/storage_serviceaccount_appengine/main.py
index 59ae325..21ec3f8 100644
--- a/samples/storage_serviceaccount_appengine/main.py
+++ b/samples/storage_serviceaccount_appengine/main.py
@@ -45,7 +45,7 @@
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
-from oauth2client.appengine import AppAssertionCredentials
+from oauth2client.contrib.appengine import AppAssertionCredentials
# Constants for the XSL stylesheet and the Google Cloud Storage URI.
XSL = '\n<?xml-stylesheet href="/listing.xsl" type="text/xsl"?>\n';
diff --git a/samples/tasks_appengine/main.py b/samples/tasks_appengine/main.py
index 9b0c856..634f39c 100644
--- a/samples/tasks_appengine/main.py
+++ b/samples/tasks_appengine/main.py
@@ -16,7 +16,7 @@
from webapp2_extras import jinja2
from googleapiclient.discovery import build
-from oauth2client.appengine import OAuth2Decorator
+from oauth2client.contrib.appengine import OAuth2Decorator
import settings