How to use the facebookads.objects.AdImage function in facebookads

To help you get started, we’ve selected a few facebookads examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebook / facebook-python-business-sdk / examples / docs / adimage.py View on Github external
],
}
images = account.get_ad_images(params=params)
# _DOC close [ADIMAGE_READ_MULTI_WITH_HASH]


# Failed to delete account image: Image with hash
# 7aa4a47d513acd589f968c833f2757b1 is still being used!
exit(0)

# _DOC open [ADIMAGE_DELETE]
# _DOC vars [image_id, ad_account_id:s, image_hash:s]
from facebookads.objects import AdImage

image = AdImage(image_id, ad_account_id)
image.remote_delete(params={AdImage.Field.hash: image_hash})
# _DOC close [ADIMAGE_DELETE]
github facebook / facebook-python-business-sdk / examples / docs / fixtures.py View on Github external
def create_image():
    image = AdImage(parent_id=test_config.account_id)
    image[AdImage.Field.filename] = test_config.image_path
    image.remote_create()

    # FIXLATER: properly delete images with dependencies

    return image
github facebook / facebook-python-business-sdk / examples / create_ad.py View on Github external
AdSet.Field.start_time: int(time.time()) + 15,  # 15 seconds from now
        AdSet.Field.campaign_group_id: campaign.get_id_assured(),
        AdSet.Field.targeting: {
            TargetingSpecsField.geo_locations: {
                'countries': [
                    'US',
                ],
            },
        },
    })
    ad_set.remote_create()
    print("**** DONE: Ad Set created:")
    pp.pprint(ad_set)

    ### Upload an image to an account.
    img = AdImage(parent_id=my_account.get_id_assured())
    img[AdImage.Field.filename] = os.path.join(
        os.path.dirname(__file__),
        os.pardir,
        'facebookads/test/misc/image.png'
    )
    img.remote_create()
    print("**** DONE: Image uploaded:")
    pp.pprint(img)  # The image hash can be found using img[AdImage.Field.hash]

    ### Create a creative.
    creative = AdCreative(parent_id=my_account.get_id_assured())
    creative.update({
        AdCreative.Field.title: 'Visit Seattle',
        AdCreative.Field.body: 'Beautiful Puget Sound!',
        AdCreative.Field.object_url: 'http://www.seattle.gov/visiting/',
        AdCreative.Field.image_hash: img.get_hash(),
github facebook / facebook-python-business-sdk / examples / docs / adimage.py View on Github external
ad_account_id = test_config.account_id
image_path = test_config.image_path
image_zip_path = test_config.images_zip_path


image = fixtures.create_image()
image_id = image[AdImage.Field.id]
image_hash = image[AdImage.Field.hash]


# _DOC open [ADIMAGE_CREATE]
# _DOC vars [ad_account_id:s, image_path:s]
from facebookads.objects import AdImage

image = AdImage(parent_id=ad_account_id)
image[AdImage.Field.filename] = image_path
image.remote_create()

# Output image Hash
print(image[AdImage.Field.hash])
# _DOC close [ADIMAGE_CREATE]


# _DOC open [ADIMAGE_CREATE_ZIP]
# _DOC vars [image_zip_path:s, ad_account_id:s]
from facebookads.objects import AdImage

images = AdImage.remote_create_from_zip(
    filename=image_zip_path,
    parent_id=ad_account_id
)
github facebook / facebook-python-business-sdk / examples / docs / adimage.py View on Github external
# 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
from facebookads.objects import AdImage

ad_account_id = test_config.account_id
image_path = test_config.image_path
image_zip_path = test_config.images_zip_path


image = fixtures.create_image()
image_id = image[AdImage.Field.id]
image_hash = image[AdImage.Field.hash]


# _DOC open [ADIMAGE_CREATE]
# _DOC vars [ad_account_id:s, image_path:s]
from facebookads.objects import AdImage

image = AdImage(parent_id=ad_account_id)
image[AdImage.Field.filename] = image_path
image.remote_create()

# Output image Hash
print(image[AdImage.Field.hash])
# _DOC close [ADIMAGE_CREATE]


# _DOC open [ADIMAGE_CREATE_ZIP]
github facebook / facebook-python-business-sdk / examples / docs / adimage.py View on Github external
# 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
from facebookads.objects import AdImage

ad_account_id = test_config.account_id
image_path = test_config.image_path
image_zip_path = test_config.images_zip_path


image = fixtures.create_image()
image_id = image[AdImage.Field.id]
image_hash = image[AdImage.Field.hash]


# _DOC open [ADIMAGE_CREATE]
# _DOC vars [ad_account_id:s, image_path:s]
from facebookads.objects import AdImage

image = AdImage(parent_id=ad_account_id)
image[AdImage.Field.filename] = image_path
image.remote_create()

# Output image Hash
print(image[AdImage.Field.hash])
# _DOC close [ADIMAGE_CREATE]
github facebook / facebook-python-business-sdk / examples / docs / fixtures.py View on Github external
def delete_image(image):
    image_hash = image[AdImage.Field.hash]
    image_id = image[AdImage.Field.id]
    image = AdImage(image_id, test_config.account_id)
    image.remote_delete(params={AdImage.Field.hash: image_hash()})