blob: eaadaf2534206fe6a60fb6cce90c40137726c2ef [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
Joe Gregorio562c9ba2013-04-05 14:24:30 -040024import argparse
Joe Gregoriob071ca72012-03-29 17:01:32 -040025import pprint
26import sys
Joe Gregoriob071ca72012-03-29 17:01:32 -040027
Joe Gregorio562c9ba2013-04-05 14:24:30 -040028from apiclient import sample_tools
29from oauth2client import client
30
31# Declare command-line flags.
32argparser = argparse.ArgumentParser(add_help=False)
33argparser.add_argument('account_id', type=int,
34 help='The ID of the account to which submit the creative')
35argparser.add_argument('cookie_matching_url',
36 help='New cookie matching URL to set for the account ')
Joe Gregoriob071ca72012-03-29 17:01:32 -040037
38
39def main(argv):
Joe Gregoriob071ca72012-03-29 17:01:32 -040040 # Authenticate and construct service.
Joe Gregorio562c9ba2013-04-05 14:24:30 -040041 service, flags = sample_tools.init(
42 argv, 'adexchangebuyer', 'v1.2', __doc__, __file__, parents=[argparser],
43 scope='https://www.googleapis.com/auth/adexchange.buyer')
44
45 account_id = flags.account_id
46 cookie_matching_url = flags.cookie_matching_url
Joe Gregoriob071ca72012-03-29 17:01:32 -040047
48 try:
49 # Account information to be updated.
50 account_body = {
51 'accountId': account_id,
52 'cookieMatchingUrl': cookie_matching_url
53 }
54 account = service.accounts().patch(id=account_id,
55 body=account_body).execute()
Joe Gregorio562c9ba2013-04-05 14:24:30 -040056 pprint.pprint(account)
57 except client.AccessTokenRefreshError:
Joe Gregoriob071ca72012-03-29 17:01:32 -040058 print ('The credentials have been revoked or expired, please re-run the '
59 'application to re-authorize')
60
61if __name__ == '__main__':
62 main(sys.argv)