我想用python學習facebook營銷api,我想用它創建我的第一個facebook活動。用facebook營銷api創建第一個活動python sdk
所以我輸入在Python Shell:
from facebookads.api import FacebookAdsApi
from facebookads import objects
my_app_id = '<APP_ID>'
my_app_secret = '<APP_SECRET>'
my_access_token = '<ACCESS_TOKEN>'
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
from facebookads.adobjects.campaign import Campaign
campaign = Campaign(parent_id='act_<AD_ACCOUNT_ID>')
campaign.update({
Campaign.Field.name: 'My First Campaign',
Campaign.Field.objective: '<LINK_CLICKS>',
})
campaign.remote_create(params={
'status': Campaign.Status.paused,
})
print(campaign)
其中i relaced: <APP_ID>
與我的應用程序ID <APP_SECRET>
與我的應用程序的祕密 <ACCESS_TOKEN>
與令牌我的ads_management <AD_ACCOUNT_ID>
我添加帳戶ID
但是我有錯誤...
Warning (from warnings module):
File "C:\Users\G\AppData\Local\Programs\Python\Python35-32\lib\site-packages\facebookads\utils\api_utils.py", line 30
warnings.warn(message)
UserWarning: value of objective might not be compatible. Expect objective_enum; got <class 'str'>
Traceback (most recent call last):
File "C:/Users/G/AppData/Local/Programs/Python/Python35-32/fb-api-test.py", line 18, in <module>
'status': Campaign.Status.paused,
File "C:\Users\G\AppData\Local\Programs\Python\Python35-32\lib\site-packages\facebookads\adobjects\abstractcrudobject.py", line 290, in remote_create
response = request.execute()
File "C:\Users\G\AppData\Local\Programs\Python\Python35-32\lib\site-packages\facebookads\api.py", line 658, in execute
api_version=self._api_version,
File "C:\Users\G\AppData\Local\Programs\Python\Python35-32\lib\site-packages\facebookads\api.py", line 325, in call
raise fb_response.error()
facebookads.exceptions.FacebookRequestError:
Message: Call was not successful
Method: POST
Path: https://graph.facebook.com/v2.7/act_<ad_account_id>/campaigns
Params: {'status': 'PAUSED', 'objective': '<LINK_CLICKS>', 'name': 'My First Campaign'}
Status: 400
Response:
{
"error": {
"message": "Invalid OAuth access token.",
"type": "OAuthException",
"fbtrace_id": "E...",
"code": 190
}
}
我還應該做些什麼才能使其工作?