Ejemplo n.º 1
0
def create_ads_pixel():
    account = AdAccount(test_config.account_id)
    pixel = account.get_ads_pixels([AdsPixel.Field.code])

    if pixel is None:
        pixel = AdsPixel(parent_id=test_config.account_id)
        pixel[AdsPixel.Field.name] = unique_name('Test Pixel')
        pixel.remote_create()

    return pixel
Ejemplo n.º 2
0
def create_ads_pixel():
    account = AdAccount(test_config.account_id)
    pixel = account.get_ads_pixels([AdsPixel.Field.code])

    if pixel is None:
        pixel = AdsPixel(parent_id=test_config.account_id)
        pixel[AdsPixel.Field.name] = unique_name('Test Pixel')
        pixel.remote_create()

    return pixel
Ejemplo n.º 3
0
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from __future__ import print_function
from __future__ import unicode_literals

from facebookads import config

# _DOC open [ADSPIXEL_CREATE]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdsPixel

pixel = AdsPixel(parent_id=ad_account_id)
pixel[AdsPixel.Field.name] = 'My new Pixel'

pixel.remote_create()
# _DOC close [ADSPIXEL_CREATE]

pixel_id = pixel.get_id()

# _DOC open [ADSPIXEL_READ_PIXEL_CODE]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdsPixel, AdAccount

account = AdAccount(ad_account_id)
account.get_ads_pixels(fields=[AdsPixel.Field.code])
# _DOC close [ADSPIXEL_READ_PIXEL_CODE]
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from examples.docs import fixtures
from facebookads import test_config

pixel = fixtures.create_ads_pixel()
pixel_id = pixel.get_id()
business_id = test_config.business_id
destination_business_id = test_config.secondary_business_id
destination_account_id = test_config.secondary_account_id

# Secondary business needs to be accessible by token
if not fixtures.can_see_business(destination_business_id):
    raise Exception("can't see secondary business " + destination_business_id)

# Secondary account needs to be accessible by token
if not fixtures.can_see_account(destination_account_id):
    raise Exception("can't see secondary account " + destination_account_id)


# _DOC open [ADSPIXEL_GET_SHARED_ADACCOUNTS_BUSINESS]
# _DOC vars [destination_business_id:s, pixel_id]
from facebookads.objects import AdsPixel, AdAccount

pixel = AdsPixel(pixel_id)
shared_accounts = pixel.get_ad_accounts(destination_business_id)
for shared_account in shared_accounts:
    print(shared_account[AdAccount.Field.id])
# _DOC close [ADSPIXEL_GET_SHARED_ADACCOUNTS_BUSINESS]
# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from examples.docs import fixtures

from facebookads import test_config

business_id = test_config.business_id
pixel_id = fixtures.create_ads_pixel().get_id()

# _DOC open [ADSPIXEL_GET_ADACCOUNTS]
# _DOC vars [business_id:s, pixel_id]
from facebookads.objects import AdsPixel, AdAccount

pixel = AdsPixel(pixel_id)
shared_accounts = pixel.get_ad_accounts(business_id)
for shared_account in shared_accounts:
    print(shared_account[AdAccount.Field.id])
# _DOC close [ADSPIXEL_GET_ADACCOUNTS]
business_id = test_config.business_id
agency_id = test_config.secondary_business_id
pixel_id = fixtures.create_ads_pixel().get_id()

# Secondary business needs to be accessible by token
if not fixtures.can_see_business(agency_id):
    raise Exception("can't see secondary business " +
                    agency_id,
                    )

# We need to unshare first in case it is already shared
fixtures.unshare_pixel_from_agency(
    pixel_id,
    business_id,
    agency_id,
)


# _DOC oncall [pestana]
# _DOC open [ADSPIXEL_SHARE_BUSINESS]
# _DOC vars [agency_id, pixel_id, business_id]
from facebookads.objects import AdsPixel

pixel = AdsPixel(pixel_id)

response = pixel.share_pixel_with_agency(business_id, agency_id)
print(response.body())
# _DOC close [ADSPIXEL_SHARE_BUSINESS]

pixel.unshare_pixel_from_agency(business_id, agency_id)
# form for use in connection with the web services and APIs provided by
# Facebook.

# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from examples.docs import fixtures

pixel_id = fixtures.create_ads_pixel().get_id()

# _DOC oncall [pruno]
# _DOC open [ADSPIXEL_GET_STATS_DEVICE_TYPE]
# _DOC vars [pixel_id]
from facebookads.objects import AdsPixel

pixel = AdsPixel(pixel_id)
pixel.get_stats(params={
    'aggregation': 'device_type',
})
# _DOC close [ADSPIXEL_GET_STATS_DEVICE_TYPE]
Ejemplo n.º 8
0
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from __future__ import print_function
from __future__ import unicode_literals

from facebookads import config


# _DOC open [ADSPIXEL_CREATE]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdsPixel

pixel = AdsPixel(parent_id=ad_account_id)
pixel[AdsPixel.Field.name] = 'My new Pixel'

pixel.remote_create()
# _DOC close [ADSPIXEL_CREATE]

pixel_id = pixel.get_id()

# _DOC open [ADSPIXEL_READ_PIXEL_CODE]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdsPixel, AdAccount

account = AdAccount(ad_account_id)
account.get_ads_pixels(fields=[AdsPixel.Field.code])
# _DOC close [ADSPIXEL_READ_PIXEL_CODE]
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from examples.docs import fixtures

pixel_id = fixtures.create_ads_pixel().get_id()

# _DOC oncall [pruno]
# _DOC open [ADSPIXEL_GET_STATS_PRODUCT_INFO_UTS]
# _DOC vars [pixel_id]
from facebookads.objects import AdsPixel
import time

pixel = AdsPixel(pixel_id)
pixel.get_stats(params={
    'aggregation': 'custom_data_field',
    'event': 'product_info',
    'start_time': int(time.time()) - 3600 * 24 * 7,
    'end_time': int(time.time()),
})
# _DOC close [ADSPIXEL_GET_STATS_PRODUCT_INFO_UTS]
# use, copy, modify, and distribute this software in source code or binary
# form for use in connection with the web services and APIs provided by
# Facebook.

# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from examples.docs import fixtures

pixel_id = fixtures.create_ads_pixel().get_id()

# _DOC open [ADSPIXEL_GET_BUSINESS]
# _DOC vars [pixel_id]
from facebookads.objects import AdsPixel, Business

pixel = AdsPixel(pixel_id)
shared_business = pixel.get_agencies()
for business in shared_business:
    print(business[Business.Field.id])
# _DOC close [ADSPIXEL_GET_BUSINESS]
Ejemplo n.º 11
0
# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from facebookads import test_config

# Impossible to create a pixel if one exists already
exit(0)

ad_account_id = test_config.account_id

# _DOC open [ADSPIXEL_CREATE]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdsPixel

pixel = AdsPixel(parent_id=ad_account_id)
pixel[AdsPixel.Field.name] = 'My new Pixel'

pixel.remote_create()
# _DOC close [ADSPIXEL_CREATE]
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from examples.docs import fixtures
from facebookads import test_config

pixel = fixtures.create_ads_pixel()
pixel_id = pixel.get_id()
business_id = test_config.business_id
account_id = test_config.account_id.replace("act_", "")

fixtures.unshare_pixel_from_account(pixel_id, business_id, account_id)
pixel.share_pixel_with_ad_account(business_id, account_id)

# _DOC oncall [pruno]
# _DOC open [ADSPIXEL_UNSHARE_ADACCOUNT]
# _DOC vars [business_id, account_id, pixel_id]
from facebookads.objects import AdsPixel

pixel = AdsPixel(pixel_id)
pixel.unshare_pixel_from_ad_account(business_id, account_id)
# _DOC close [ADSPIXEL_UNSHARE_ADACCOUNT]

pixel.share_pixel_with_ad_account(business_id, account_id)
from facebookads import test_config

pixel_id = fixtures.create_ads_pixel().get_id()
business_id = test_config.business_id
destination_account_id = test_config.account_id.replace("act_", "")

# _DOC oncall [pestana]
fixtures.unshare_pixel_from_account(
    pixel_id,
    business_id,
    destination_account_id,
)

# _DOC open [ADSPIXEL_SHARE_ADACCOUNT]
# _DOC vars [business_id:s, destination_account_id:s, pixel_id]
from facebookads.objects import AdsPixel

pixel = AdsPixel(pixel_id)

response = pixel.share_pixel_with_ad_account(
    business_id,
    destination_account_id,
)
print(response.body())
# _DOC close [ADSPIXEL_SHARE_ADACCOUNT]

pixel.unshare_pixel_from_ad_account(
    business_id,
    destination_account_id,
)