def get_businesses(self):
     """
         Retrieves business account of the user's ad accounts.
     """
     me = AdAccountUser(fbid='me')
     businesses = me.remote_read(fields=['businesses'])
     return businesses['businesses']['data']
Ejemplo n.º 2
0
 def get_accounts(self):
     """
       Retrieves and displays a list of the user's ad accounts.
      """
     me = AdAccountUser(fbid='me')
     return list(
         me.get_ad_accounts(fields=[
             'id', 'name', 'timezone_name', 'amount_spent', 'currency'
         ]))
    def get_my_account(cls, api=None):
        from facebook_business.adobjects.adaccountuser import AdAccountUser
        """Returns first AdAccount associated with 'me' given api instance."""
        # Setup user and read the object from the server
        me = AdAccountUser(fbid='me', api=api)

        # Get first account connected to the user
        my_account = me.edge_object(cls)

        return my_account
Ejemplo n.º 4
0
def get_page_insight(request):
    my_app_id = SocialApp.client_id
    my_app_secret = '0e51c739872e518f388fbf1439b6d7e7'
    my_access_token = 'EAAt6AfVaOUABAJZBOoHMic2IZAADP3QpJyRwev57FUJIvkSUtAo5ZATcmYLb7EgqOLZB0RAhHKYupyxnbmRlDzjRJDtSKKjCnR6KaVw0n3HnHM6FsKf4We9ynZBVjrBs9GfDdSm4y94bZCcJjLHv56npCfrHWn3WBRePPs6mD4WwZDZD'
    FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
    me = AdUser(fbid='me')
    my_pages = me.get_pages(fields=[Page.Field.name, Page.Field.id])
    my_ad_account = me.get_ad_accounts(
        fields=[AdAccount.Field.name, AdAccount.Field.id])
    pass
Ejemplo n.º 5
0
    def get_my_account(cls, api=None):
        from facebook_business.adobjects.adaccountuser import AdAccountUser
        """Returns first AdAccount associated with 'me' given api instance."""
        # Setup user and read the object from the server
        me = AdAccountUser(fbid='me', api=api)

        # Get first account connected to the user
        my_account = me.edge_object(cls)

        return my_account
Ejemplo n.º 6
0
def get_facebook_page(request):
    my_app_id = SocialApp.client_id
    my_app_secret = '0e51c739872e518f388fbf1439b6d7e7'
    my_access_token = 'EAAt6AfVaOUABAJZBOoHMic2IZAADP3QpJyRwev57FUJIvkSUtAo5ZATcmYLb7EgqOLZB0RAhHKYupyxnbmRlDzjRJDtSKKjCnR6KaVw0n3HnHM6FsKf4We9ynZBVjrBs9GfDdSm4y94bZCcJjLHv56npCfrHWn3WBRePPs6mD4WwZDZD'
    FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
    me = AdUser(fbid='me')
    my_pages = me.get_pages(fields=[Page.Field.name, Page.Field.id])
    my_ad_account = me.get_ad_accounts(
        fields=[AdAccount.Field.name, AdAccount.Field.id])
    namesAndAccIds = []
    namesAndAdaccIDs = []
    account_insieght = []
    page_likes = []
    for account in my_pages:
        namesAndAccIds.append((account['name'], account['id']))
    for adaccount in my_ad_account:
        namesAndAdaccIDs.append((adaccount['name'], adaccount['id']))
    return render(request, 'index.html', locals())
Ejemplo n.º 7
0
### Setup session and api objects
session = FacebookSession(
    config['app_id'],
    config['app_secret'],
    config['access_token'],
)
api = FacebookAdsApi(session)

if __name__ == '__main__':
    FacebookAdsApi.set_default_api(api)

    print('\n\n\n********** Reading objects example. **********\n')

    ### Setup user and read the object from the server
    me = AdUser(fbid='me')

    ### Read user permissions
    print('>>> Reading permissions field of user:'******'>>> Reading accounts associated with user')
Ejemplo n.º 8
0
from facebook_business.adobjects.adaccountuser import AdAccountUser as AdUser


def fun1():
    print('ssssss')

my_app_id = 'xx'
my_app_secret = 'xx'
my_access_token = 'xx'
FacebookAdsApi.init(my_app_id,my_app_secret,my_access_token)

# act = AdAccount("act_599679690213860")
# campaigns = act.get_campaigns()
# print(campaigns)

me = AdUser(fbid='me')
my_accounts = me.get_ad_accounts(params={'limit':10})
# print(my_accounts)
allAct = []
page = 1
print(type(my_accounts))
print('page=',page)
for act in my_accounts:
    print(type(act))
    page += 1
    print('page=', page,'========')
    print(act[AdAccount.Field.id])


# while my_accounts.g:
#     allAct.append(my_accounts)
Ejemplo n.º 9
0
from facebook_business.api import FacebookAdsApi
from facebook_business import adobjects
from facebook_business.adobjects.adaccountuser import AdAccountUser
from facebook_business.adobjects.campaign import Campaign
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.adsinsights import AdsInsights
from facebook_business.adobjects.adreportrun import AdReportRun
import json
import time
import env

print(env.token())
FacebookAdsApi.init(access_token=env.token())
me = AdAccountUser(fbid='me')
ad_accounts = me.get_ad_accounts()
# print(ad_accounts)
params = {
    'level':
    'ad',
    'fields': [
        AdsInsights.Field.campaign_id, AdsInsights.Field.campaign_name,
        AdsInsights.Field.adset_name, AdsInsights.Field.ad_name,
        AdsInsights.Field.spend, AdsInsights.Field.impressions,
        AdsInsights.Field.clicks, AdsInsights.Field.buying_type,
        AdsInsights.Field.objective, AdsInsights.Field.actions
    ],
    # 'breakdowns': [AdsInsights.Breakdown.hourly_stats_aggregated_by_advertiser_time_zone],
    'time_range': {
        'since': "2019-11-02",
        'until': "2020-02-17"
    },
### Setup session and api objects
session = FacebookSession(
    config['app_id'],
    config['app_secret'],
    config['access_token'],
)
api = FacebookAdsApi(session)

if __name__ == '__main__':
    FacebookAdsApi.set_default_api(api)

    print('\n\n\n********** Reading objects example. **********\n')

    ### Setup user and read the object from the server
    me = AdUser(fbid='me')

    ### Read user permissions
    print('>>> Reading permissions field of user:'******'>>> Reading accounts associated with user')
Ejemplo n.º 11
0
    def __init__(self, app_id, app_secret, access_token):
        FacebookAdsApi.init(app_id, app_secret, access_token)
        print('Приложение успешно иницилизировано')

        me = me = AdAccountUser(fbid='me')
        self.my_account = me.get_ad_accounts()[0]
Ejemplo n.º 12
0
#reading file containing keys
with open('secretfb.txt') as file:
    for line in file:
        l = line
        keys.append(l)
app_id = keys[0]
app_secret = keys[1]
token = keys[2]
ad_account_id = keys[3]

#print(app_id,app_secret,token,ad_account_id)

FacebookAdsApi.init(access_token=token)

#Account ID
me = AdAccountUser(fbid='me')
my_account = me.get_ad_accounts()[0]
Account_id = my_account['id']


#initializing accountid to classs object
class Account(object):
    def __init__(self, account_id):
        self.account_id = account_id


new_acc = Account(account_id=Account_id)

campaigns = my_account.get_campaigns()
print(campaigns)
campaign = Campaign(new_acc.account_id)
Ejemplo n.º 13
0
from django.shortcuts import render
from bson.json_util import dumps
from django.http import HttpResponse, JsonResponse
from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.campaign import Campaign as AdCampaign
from facebook_business.adobjects.adaccountuser import AdAccountUser as AdUser
from facebook_business.adobjects.adset import AdSet
from allauth.socialaccount.models import (SocialAccount, SocialApp,
                                          SocialToken)

import os

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

my_app_id = SocialApp.client_id
my_app_secret = '0e51c739872e518f388fbf1439b6d7e7'
my_access_token = 'EAAt6AfVaOUABAJZBOoHMic2IZAADP3QpJyRwev57FUJIvkSUtAo5ZATcmYLb7EgqOLZB0RAhHKYupyxnbmRlDzjRJDtSKKjCnR6KaVw0n3HnHM6FsKf4We9ynZBVjrBs9GfDdSm4y94bZCcJjLHv56npCfrHWn3WBRePPs6mD4WwZDZD'
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
me = AdUser(fbid='me')
my_account = me.get_ad_account()
for campaign in my_account.get_ad_campaigns(fields=[AdCampaign.Field.name]):
    for stat in campaign.get_stats(fields=[
            'impressions',
            'clicks',
            'spent',
            'unique_clicks',
            'actions',
    ]):
        print(campaign[campaign.Field.name])