facebook / facebook-python-business-sdk

Python SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
1.29k stars 635 forks source link

No module named "facebookads.adobjects.adaccount" #495

Closed alula12002 closed 6 years ago

alula12002 commented 6 years ago

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.

ntnam11 commented 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

alula12002 commented 6 years ago

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, )

ntnam11 commented 6 years ago

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?

alula12002 commented 6 years ago

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" } }

ntnam11 commented 6 years ago
  1. Check if you have access to the ad account id. If your Facebook app is in development stage, you must own that ad account, or the person who owns the ad account must have a role in your app.
  2. Check if your Facebook app requested ads_read and ads_management permissions from app user
  3. Try again in a few minutes (as the message is temporarily unavailable)
mikerudine commented 6 years ago

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

vicdus commented 6 years ago

Thanks! We will remove the old sample code files and commit new samples.