简体   繁体   English

python请求是否支持@符号表示文件上传?

[英]Does python requests support @ notation for file upload?

I ask because the examples in the Facebook Ads API ( https://developers.facebook.com/docs/reference/ads-api/adimage/#create ) for creating an Ad Image all use curl, but I want to do it with python requests. 我问是因为Facebook Ads API( https://developers.facebook.com/docs/reference/ads-api/adimage/#create )中用于创建广告图片的示例都使用curl,但是我想这样做python请求。 Or if someone can answer the more specific question of how to create an Ad Image on the Facebook Ads API from python, that'd be great as well. 或者,如果有人可以回答更具体的问题,即如何使用python在Facebook Ads API上创建广告图像,那也很好。 You can assume I have the location on disk of the image file to upload. 您可以假设我在要上传的图像文件的磁盘上有该位置。 Should be a simple POST request to the endpoint /act_[account_id]/adimages, right? 是对端点/ act_ [account_id] / adimages的简单POST请求,对吗?

I would use something like this: 我会用这样的东西:

Or you might want to check out this answer: 或者您可能想查看以下答案:

Personally, I would think you could use a mixture of Facebook Python SDK and requests 就个人而言,我认为您可以混合使用Facebook Python SDK和请求

I've written a Python client for Facebook Ads API, it's very simple to use: https://github.com/rpedigoni/fbads 我已经为Facebook Ads API编写了Python客户端,使用起来非常简单: https//github.com/rpedigoni/fbads

You can make ad creatives without uploading the images, using its URL directly, see this example: 您可以直接使用其URL制作广告创意而无需上传图像,请参见以下示例:

fbads = FBAds(account_id='1378857852381224', access_token='a_valid_token')
creative_id = fbads.creative.add(
    title=u'Test creative',
    body=u'Testing creative creation! Lorem ipsum here.',
    link_url='http://fbads.readthedocs.org/en/latest/index.html',
    image_url='https://d1dhh18vvfes41.cloudfront.net/417x300/051057500.jpg',
)

https://github.com/rpedigoni/fbads/blob/master/tests/test_creative.py#L8 https://github.com/rpedigoni/fbads/blob/master/tests/test_creative.py#L8

Apologies if this is too late, but just in case it isn't, you can use the official Facebook Python Ads API SDK . 抱歉,为时已晚,但以防万一,请使用官方的Facebook Python Ads API SDK

You can create an Ad Image using this code (from docs ): 您可以使用以下代码(来自docs )创建广告图像:

from facebookads.objects import AdImage

image = AdImage(parent_id='act_<AD_ACCOUNT_ID>')
image[AdImage.Field.filename] = './test.jpg'
image.remote_create()

# Image Hash
print image[AdImage.Field.hash]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM