My favorites | Sign in
Project Logo
                
Changes to /trunk/v3/samplecode/GenerateAdCodeSnippet.py
r2 vs. r3   Edit
  Compare: r2 vs. r3   Format:
Revision r3
Go to: 
Project members, sign in to write a code review
/trunk/v3/GenerateAdCodeSnippet.py   r2 /trunk/v3/samplecode/GenerateAdCodeSnippet.py   r3
1 #!/usr/bin/python2.2 1 #!/usr/bin/python2.2
2 # 2 #
3 # Copyright 2006, Google Inc. All Rights Reserved. 3 # Copyright 2006, Google Inc. All Rights Reserved.
4 4
5 ##################################################################### 5 #####################################################################
6 # Sample code to add a generate ad code snippet through Adsense API # 6 # Sample code to add a generate ad code snippet through Adsense API #
7 ##################################################################### 7 #####################################################################
8 8
9 import SOAPpy 9 import SOAPpy
10 10
11 server = "https://sandbox.google.com" 11 server = "https://sandbox.google.com"
12 12
13 dev_email = "REPLACE WITH DEVELOPER EMAIL" 13 dev_email = "REPLACE WITH DEVELOPER EMAIL"
14 dev_password = "REPLACE WITH DEVELOPER PASSWORD" 14 dev_password = "REPLACE WITH DEVELOPER PASSWORD"
15 client_id = "REPLACE WITH CLIENT ID" 15 client_id = "REPLACE WITH CLIENT ID"
16 16
17 # Set headers 17 # Set headers
18 headers = SOAPpy.Types.headerType() 18 headers = SOAPpy.Types.headerType()
19 headers.developer_email = dev_email 19 headers.developer_email = dev_email
20 headers.developer_password = dev_password 20 headers.developer_password = dev_password
21 headers.client_id = client_id 21 headers.client_id = client_id
22 22
23 # Set service connection 23 # Set service connection
24 service = SOAPpy.SOAPProxy( 24 service = SOAPpy.SOAPProxy(
25 server + "/api/adsense/v3/AccountService", 25 server + "/api/adsense/v3/AccountService",
26 namespace="http://www.google.com/api/adsense/v3", 26 namespace="http://www.google.com/api/adsense/v3",
27 header=headers) 27 header=headers)
28 # To view xml request/response set service.config.debug = 1 28 # To view xml request/response set service.config.debug = 1
29 service.config.debug = 0 29 service.config.debug = 0
30 30
31 syn_service_type = SOAPpy.Types.structType(name="synServiceTypes") 31 syn_service_type = SOAPpy.Types.structType(name="synServiceTypes")
32 syn_service_type._addItem(name="value",value="ContentAds") 32 syn_service_type._addItem(name="value",value="ContentAds")
33 33
34 # Get the Syndication ID 34 # Get the Syndication ID
35 # Might throw a soap exception on user input or error upon trying to connect 35 # Might throw a soap exception on user input or error upon trying to connect
36 response = service.getSyndicationService(syn_service_type) 36 response = service.getSyndicationService(syn_service_type)
37 syn_id = response["id"] 37 syn_id = response["id"]
38 print "syn id :", syn_id 38 print "syn id :", syn_id
39 print 39 print
40 40
41 # Set another service connetion 41 # Set another service connetion
42 service = SOAPpy.SOAPProxy( 42 service = SOAPpy.SOAPProxy(
43 server + "/api/adsense/v3/AdSenseForContentService", 43 server + "/api/adsense/v3/AdSenseForContentService",
44 namespace="http://www.google.com/api/adsense/v3", 44 namespace="http://www.google.com/api/adsense/v3",
45 header=headers) 45 header=headers)
46 service.config.debug = 0 46 service.config.debug = 0
47 47
48 # Set up the ad style 48 # Set up the ad style
49 ad_style_template = """ 49 ad_style_template = """
50 <backgroundColor>%s</backgroundColor> 50 <backgroundColor>%s</backgroundColor>
51 <borderColor>%s</borderColor> 51 <borderColor>%s</borderColor>
52 <name>%s</name> 52 <name>%s</name>
53 <textColor>%s</textColor> 53 <textColor>%s</textColor>
54 <titleColor>%s</titleColor> 54 <titleColor>%s</titleColor>
55 <urlColor>%s</urlColor> 55 <urlColor>%s</urlColor>
56 """ 56 """
57 57
58 ad_style = ad_style_template % ('#FFFFFF', '#0000FF', 'demoStyle', 58 ad_style = ad_style_template % ('#FFFFFF', '#0000FF', 'demoStyle',
59 '#00FF00', '#FF0000', '#FFFF00') 59 '#00FF00', '#FF0000', '#FFFF00')
60 ad_style = SOAPpy.Types.untypedType(name="adStyle",data=ad_style) 60 ad_style = SOAPpy.Types.untypedType(name="adStyle",data=ad_style)
61 #ad_style._setAttr( 61 #ad_style._setAttr(
62 # 'xmlns:impl', 62 # 'xmlns:impl',
63 # 'http://www.google.com/api/adsense/v3') 63 # 'http://www.google.com/api/adsense/v3')
64 #ad_style._setAttr('xsi:type', 'impl:AdStyle') 64 #ad_style._setAttr('xsi:type', 'impl:AdStyle')
65 65
66 # Set up other parameters 66 # Set up other parameters
67 syn_service_id = SOAPpy.Types.untypedType(name="synServiceId",data=syn_id) 67 syn_service_id = SOAPpy.Types.untypedType(name="synServiceId",data=syn_id)
68 ad_unit_type = SOAPpy.Types.structType(name="adUnitType") 68 ad_unit_type = SOAPpy.Types.structType(name="adUnitType")
69 ad_unit_type._addItem(name="value",value="TextOnly") 69 ad_unit_type._addItem(name="value",value="TextOnly")
70 layout = SOAPpy.Types.structType(name="adLayout") 70 layout = SOAPpy.Types.structType(name="adLayout")
71 layout._addItem(name="value",value="728x90") 71 layout._addItem(name="value",value="728x90")
72 alternate = SOAPpy.Types.untypedType(name="alternate",data="#FFFFFF") 72 alternate = SOAPpy.Types.untypedType(name="alternate",data="#FFFFFF")
73 is_framed_page = SOAPpy.Types.untypedType(name="isFramedPage",data="False") 73 is_framed_page = SOAPpy.Types.untypedType(name="isFramedPage",data="False")
74 channel_name = SOAPpy.Types.untypedType(name="channelName",data="") 74 channel_name = SOAPpy.Types.untypedType(name="channelName",data="")
75 corner_styles = SOAPpy.Types.structType(name="cornerStyles") 75 corner_styles = SOAPpy.Types.structType(name="cornerStyles")
76 corner_styles._addItem(name="value",value="DEFAULT") 76 corner_styles._addItem(name="value",value="DEFAULT")
77 77
78 # Generate ad code, might throw a soap exception 78 # Generate ad code, might throw a soap exception
79 # on user input or error upon trying to connect 79 # on user input or error upon trying to connect
80 response = service.generateAdCode(syn_service_id, ad_style, ad_unit_type, 80 response = service.generateAdCode(syn_service_id, ad_style, ad_unit_type,
81 layout, alternate, is_framed_page, 81 layout, alternate, is_framed_page,
82 channel_name,corner_styles) 82 channel_name,corner_styles)
83 83
84 print "Ad code snippet :" 84 print "Ad code snippet :"
85 print response 85 print response
Hosted by Google Code