Example #1
0
def main_impl():
    args = utils.parse_args(REQUIRED_CONFIG_KEYS)
    account_id = args.config['account_id']
    access_token = args.config['access_token']

    CONFIG.update(args.config)

    FacebookAdsApi.init(access_token=access_token)
    user = fb_user.User(fbid='me')
    accounts = user.get_ad_accounts()
    account = None
    for acc in accounts:
        if acc['account_id'] == account_id:
            account = acc
    if not account:
        raise TapFacebookException(
            "Couldn't find account with id {}".format(account_id))

    if args.discover:
        do_discover()
    elif args.properties:
        catalog = Catalog.from_dict(args.properties)
        do_sync(account, catalog, args.state)
    else:
        LOGGER.info("No properties were selected")
Example #2
0
    def _find_accounts(self) -> List[Mapping[str, Any]]:
        try:
            instagram_business_accounts = []
            accounts = fb_user.User(fbid="me").get_accounts()
            for account in accounts:
                page = Page(account.get_id()).api_get(
                    fields=["instagram_business_account"])
                if page.get("instagram_business_account"):
                    instagram_business_accounts.append({
                        "page_id":
                        account.get_id(),
                        "instagram_business_account":
                        IGUser(
                            page.get("instagram_business_account").get("id")),
                    })
        except FacebookRequestError as exc:
            raise InstagramAPIException(
                f"Error: {exc.api_error_code()}, {exc.api_error_message()}"
            ) from exc

        if not instagram_business_accounts:
            raise InstagramAPIException(
                "Couldn't find an Instagram business account for current Access Token"
            )

        return instagram_business_accounts
Example #3
0
def main_impl():
    args = utils.parse_args(REQUIRED_CONFIG_KEYS)
    account_id = args.config['account_id']
    account_ids = account_id.split(",")
    access_token = args.config['access_token']

    CONFIG.update(args.config)

    global RESULT_RETURN_LIMIT
    RESULT_RETURN_LIMIT = CONFIG.get('result_return_limit',
                                     RESULT_RETURN_LIMIT)

    global API
    API = FacebookAdsApi.init(access_token=access_token)
    user = fb_user.User(fbid='me')
    accounts = user.get_ad_accounts()
    selected_accounts = []
    for acc in accounts:
        if acc['account_id'] in account_ids:
            selected_accounts.append(acc)
    if len(selected_accounts) < 1:
        raise TapFacebookException(
            "Couldn't find account with id {}".format(account_id))

    if args.discover:
        do_discover()
    elif args.properties:
        catalog = Catalog.from_dict(args.properties)
        for account in selected_accounts:
            singer.logger.log_info("syncing account " +
                                   str(account["account_id"]))
            do_sync(account, catalog, args.state)
    else:
        LOGGER.info("No properties were selected")
Example #4
0
def main_impl():
    args = parse_args(REQUIRED_CONFIG_KEYS)
    account_id = args.config['account_id']
    access_token = args.config['access_token']

    global auth
    auth = [account_id, access_token]

    CONFIG.update(args.config)

    global RESULT_RETURN_LIMIT
    RESULT_RETURN_LIMIT = CONFIG.get('result_return_limit', RESULT_RETURN_LIMIT)

    global API
    API = FacebookAdsApi.init(access_token=access_token)
    user = fb_user.User(fbid='me')
    accounts = user.get_ad_accounts()
    account = None
    for acc in accounts:
        if acc['account_id'] == account_id:
            account = acc
    if not account:
        raise TapFacebookException("Couldn't find account with id {}".format(account_id))

    if args.discover:
        do_discover(args.select_all)
    elif args.properties:
        catalog = Catalog.from_dict(args.properties)
        do_sync(account, catalog, args.state)
    elif args.catalog:
        do_sync(account, args.catalog, args.state)
    else:
        LOGGER.info("No properties were selected")
Example #5
0
    def _find_account(account_id: str):
        try:
            accounts = fb_user.User(fbid="me").get_ad_accounts()
            for account in accounts:
                if account["account_id"] == account_id:
                    return account
        except FacebookRequestError as exc:
            raise FacebookAPIException(f"Error: {exc.api_error_code()}, {exc.api_error_message()}") from exc

        raise FacebookAPIException("Couldn't find account with id {}".format(account_id))
Example #6
0
def _get_ad_accounts() -> [adaccount.AdAccount]:
    """Retrieves the ad accounts of the user whose access token was provided and
    returns them as a list.

    Returns:
        A list of ad accounts

    """
    system_user = user.User(fbid='me')
    ad_accounts = system_user.get_ad_accounts(fields=[
        'account_id', 'name', 'created_time', 'timezone_offset_hours_utc'
    ])
    return list(ad_accounts)
Example #7
0
def main_impl():
    try:
        args = utils.parse_args(REQUIRED_CONFIG_KEYS)
        account_id = args.config['account_id']
        access_token = args.config['access_token']

        CONFIG.update(args.config)

        global RESULT_RETURN_LIMIT
        RESULT_RETURN_LIMIT = CONFIG.get('result_return_limit',
                                         RESULT_RETURN_LIMIT)

        global API
        API = FacebookAdsApi.init(access_token=access_token)
        user = fb_user.User(fbid='me')

        accounts = user.get_ad_accounts()
        account = None
        for acc in accounts:
            if acc['account_id'] == account_id:
                account = acc
        if not account:
            raise SingerConfigurationError(
                "Couldn't find account with id {}".format(account_id))
    except FacebookError as fb_error:
        raise_from(SingerConfigurationError, fb_error)

    if args.discover:
        try:
            do_discover()
        except FacebookError as fb_error:
            raise_from(SingerDiscoveryError, fb_error)
    elif args.properties:
        catalog = Catalog.from_dict(args.properties)
        try:
            do_sync(account, catalog, args.state)
        except FacebookError as fb_error:
            raise_from(SingerSyncError, fb_error)
    else:
        LOGGER.info("No properties were selected")
Example #8
0
 def _get_accounts(self) -> Cursor:
     return fb_user.User(fbid="me").get_accounts()