def testInitDfpClientWithClientLoginNotSupported(self):
        """Ensures the DFP library throws an error for clientLogin on > v201311."""

        headers = {
            'authToken': 'THIS IS A NO NO AFTER v201311!',
            'applicationName': 'APPLICATION NAME MUST NOT BE EMPTY'
        }
        client = DfpClient(headers=headers)
        with mock.patch('adspygoogle.SOAPpy.WSDL.Proxy'):
            network_service_fine = client.GetNetworkService(version='v201311')
            self.assertRaises(ApiVersionNotSupportedError,
                              client.GetNetworkService,
                              version='v201403')
示例#2
0
class DoubleClickNetwork(BaseNetwork):
    VERSION = 'v201306'
    AD_UNIT_PREFIX = 'TheCrimson'
    MOBILE_KEY = 'Mobile'
    DESKTOP_KEY = 'Desktop'

    def __init__(self):
        auth = dict(settings.DFP_HEADERS)
        auth['oauth2credentials'] = OAuth2Credentials(
            None, auth['clientId'], auth['clientSecret'], auth['refreshToken'],
            datetime.datetime(1980, 1, 1, 12), _GOOGLE_OAUTH2_ENDPOINT,
            'Google Ads* Python Client Library')
        self.client = DfpClient(headers=auth, config=settings.DFP_CONFIG)

    def get_root_node_id(self):
        network_service = self.client.GetNetworkService(version=self.VERSION)
        network = network_service.GetCurrentNetwork()[0]
        return network['effectiveRootAdUnitId']

    def _update_ad_units(self):
        inventory = self.client.GetInventoryService(version=self.VERSION)
        values = [{
            'key': 'parentId',
            'value': {
                'xsi_type': 'TextValue',
                'value': self.get_root_node_id()
            }
        }]
        filter_statement = {
            'query': "WHERE status = 'ACTIVE' AND parentId = :parentId",
            'values': values
        }
        ad_units = inventory.GetAdUnitsByStatement(filter_statement)[0]
        ad_units = ad_units.get('results', [])
        for ad_unit in ad_units:
            if not ad_unit['adUnitCode'].startswith(self.AD_UNIT_PREFIX):
                continue

            AdUnit.objects.create_or_update(
                code=ad_unit['adUnitCode'],
                network_id=ad_unit['id'],
                size=ad_unit['adUnitSizes'][0]['fullDisplayString'],
                display_on=AdUnit.MOBILE_AND_DESKTOP)
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This example gets the current network that you can make requests against."""

__author__ = '[email protected] (Stan Grinberg)'

# Locate the client library. If module was installed via "setup.py" script, then
# the following two lines are not needed.
import os
import sys
sys.path.append(os.path.join('..', '..', '..', '..'))

# Import appropriate classes from the client library.
from adspygoogle.dfp.DfpClient import DfpClient

# Initialize client object.
client = DfpClient(path=os.path.join('..', '..', '..', '..'))

# Initialize appropriate service. By default, the request is always made against
# the sandbox environment.
network_service = client.GetNetworkService('https://sandbox.google.com',
                                           'v201103')

# Get the current network.
network = network_service.GetCurrentNetwork()[0]

# Display results.
print('Current network has network code \'%s\' and display name \'%s\'.' %
      (network['networkCode'], network['displayName']))