blob: 43fc357e00850aa681901c37ef774d0de9ad0c37 [file] [log] [blame]
Craig Citro15744b12015-03-02 13:34:32 -08001#!/usr/bin/env python
Joe Gregorio4c46b7b2012-03-20 14:29:56 -04002# -*- coding: utf-8 -*-
3#
Craig Citro751b7fb2014-09-23 11:20:38 -07004# Copyright 2014 Google Inc. All Rights Reserved.
Joe Gregorio4c46b7b2012-03-20 14:29:56 -04005#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18"""Simple command-line sample that demonstrates service accounts.
19
20Lists all the Google Task Lists associated with the given service account.
21Service accounts are created in the Google API Console. See the documentation
22for more information:
23
24 https://developers.google.com/console/help/#WhatIsKey
25
26Usage:
27 $ python tasks.py
28"""
29
30__author__ = 'jcgregorio@google.com (Joe Gregorio)'
31
32import httplib2
33import pprint
34import sys
35
John Asmuth864311d2014-04-24 15:46:08 -040036from googleapiclient.discovery import build
Adrian Carpenter2122d3c2016-02-16 16:12:22 -060037from oauth2client.service_account import ServiceAccountCredentials
Joe Gregorio4c46b7b2012-03-20 14:29:56 -040038
39def main(argv):
Adrian Carpenter2122d3c2016-02-16 16:12:22 -060040 # Load the json format key that you downloaded from the Google API
41 # Console when you created your service account. For p12 keys, use the
42 # from_p12_keyfile method of ServiceAccountCredentials and specify the
43 # service account email address, p12 keyfile, and scopes.
44 credentials = ServiceAccountCredentials.from_json_keyfile_name(
45 'service-account-abcdef123456.json',
46 scopes='https://www.googleapis.com/auth/tasks')
Joe Gregorio4c46b7b2012-03-20 14:29:56 -040047
Adrian Carpenter2122d3c2016-02-16 16:12:22 -060048 # Create an httplib2.Http object to handle our HTTP requests and authorize
49 # it with the Credentials.
Joe Gregorio4c46b7b2012-03-20 14:29:56 -040050 http = httplib2.Http()
51 http = credentials.authorize(http)
52
53 service = build("tasks", "v1", http=http)
54
55 # List all the tasklists for the account.
Joe Gregorio68a8cfe2012-08-03 16:17:40 -040056 lists = service.tasklists().list().execute(http=http)
Joe Gregorio4c46b7b2012-03-20 14:29:56 -040057 pprint.pprint(lists)
58
59
60if __name__ == '__main__':
61 main(sys.argv)