blob: eaf17a994b92c6e5da14aabb731d031a53a58166 [file] [log] [blame]
Joe Gregoriob071ca72012-03-29 17:01:32 -04001#!/usr/bin/python
2#
3# Copyright 2012 Google Inc. All Rights Reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""This example illustrates how to do a sparse update of the account attributes.
18
19Tags: accounts.patch
20"""
21
22__author__ = 'david.t@google.com (David Torres)'
23
24import pprint
25import sys
26import gflags
27from oauth2client.client import AccessTokenRefreshError
28import sample_utils
29
30# Declare command-line flags, and set them as required.
31gflags.DEFINE_string('account_id', None,
32 'The ID of the account to which submit the creative',
33 short_name='a')
34gflags.MarkFlagAsRequired('account_id')
35gflags.DEFINE_string('cookie_matching_url', None,
36 'New cookie matching URL to set for the account ',
37 short_name='u')
38gflags.MarkFlagAsRequired('cookie_matching_url')
39
40
41def main(argv):
42 sample_utils.process_flags(argv)
43 account_id = gflags.FLAGS.account_id
44 cookie_matching_url = gflags.FLAGS.cookie_matching_url
45 pretty_printer = pprint.PrettyPrinter()
46
47 # Authenticate and construct service.
48 service = sample_utils.initialize_service()
49
50 try:
51 # Account information to be updated.
52 account_body = {
53 'accountId': account_id,
54 'cookieMatchingUrl': cookie_matching_url
55 }
56 account = service.accounts().patch(id=account_id,
57 body=account_body).execute()
58 pretty_printer.pprint(account)
59 except AccessTokenRefreshError:
60 print ('The credentials have been revoked or expired, please re-run the '
61 'application to re-authorize')
62
63if __name__ == '__main__':
64 main(sys.argv)