Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
],
}
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]
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
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(),
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
)
# 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]
# 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]
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()})