Closed alula12002 closed 6 years ago
Did you install the Facebook Marketing API? You can check it in your Python Lib/site-packages
directory. If not, then you need to run sudo python pip install facebook_business
first
Facebook Marrketing API changed from facebookads
to facebook_business
since version 3.0, so you need to change your import line to: from facebook_business.adobjects.adaccount import AdAccount
Yes, it was installed- the issue was facebookads. I changed the line as you directed and now when I run the code I don't get an error but just "[ ]". Not sure why this is. Here's my Sample Code:
from facebook_business.adobjects.adaccount import AdAccount from facebook_business.adobjects.adsinsights import AdsInsights from facebook_business.api import FacebookAdsApi
access_token = 'my token' ad_account_id = 'act_2096707320609866' app_secret = 'my secret' app_id = 'my app id' FacebookAdsApi.init(access_token=access_token)
fields = [ 'reach', 'frequency', 'impressions', 'spend', 'cpm', 'clicks', 'account_id', 'account_name', 'campaign_name', 'campaign_id', 'date_stop', 'date_start', ] params = { 'level': 'ad', 'filtering': [], 'breakdowns': ['age','gender'], 'time_range': {'since':'2018-05-16','until':'2018-06-15'}, } print AdAccount(ad_account_id).get_insights( fields=fields, params=params, )
I modified your code to run on python 3.6.6 with my own access_token
and ad_account_id
and it's fine. Is there data in your ad_account_id
?
I thought that too, but when I try other ad account id's I get this:
_facebook_business.exceptions.FacebookRequestError:
Message: Call was not successful Method: GET Path: https://graph.facebook.com/v3.0/act_1405842649541540/insights Params: {'fields': 'reach,frequency,impressions,spend,cpm,clicks,account_id,account_name,campaign_name,campaign_id,date_stop,date_start', 'time_range': '{"since":"2018-05-16","until":"2018-06-15"}'}
Status: 400 Response: { "error": { "code": 2, "message": "(#2) Service temporarily unavailable", "is_transient": true, "type": "OAuthException", "fbtraceid": "EmLXAaSO3bF" } }
ads_read
and ads_management
permissions from app usertemporarily unavailable
)Thats wrong Sample Code, old version, as i know
https://github.com/facebook/facebook-python-business-sdk/issues/331
use from facebookads.adobjects import or if you got Business SDK you need to change facebookads on facebook_business
Thanks! We will remove the old sample code files and commit new samples.
I'm trying to run sample code downloaded from the Marketing API's quickstart guide, and when I run the command "sudo python SAMPLE_CODE.py" I get the following error:
_Traceback (most recent call last): File "SAMPLECODE.py", line 21, in
from facebookads.adobjects.adaccount import AdAccount
ImportError: No module named facebookads.adobjects.adaccount
Anyone know what's going on here? Thanks.