Ejemplo n.º 1
0
def view_adset(request):
    FacebookAdsApi.init(access_token=access_token,
                        app_id=app_id,
                        app_secret=app_secret)

    my_account = AdAccount('act_' + user_id)

    adsets = my_account.get_ad_sets()
    adset_id = []
    for i in range(len(adsets)):
        adset_id.append(adsets[i]["id"])

    adset_data = []
    for id in adset_id:
        adset = AdSet(fbid=id)
        fields = [
            AdSet.Field.name,
            AdSet.Field.effective_status,
            AdSet.Field.campaign_id,
            AdSet.Field.status,
        ]
        adset.remote_read(fields=fields)

        result = {}
        result["id"] = id
        result["name"] = adset[AdSet.Field.name]
        result["campid"] = adset[AdSet.Field.campaign_id]
        result["status"] = adset[AdSet.Field.status]
        result["data_1"] = "ACTIVE"
        result["data_2"] = "PAUSED"
        adset_data.append(result)

    context = {'adsets': adset_data}

    return render(request, 'fbapp/view_adset.html', context)
Ejemplo n.º 2
0
    def enable_an_on_adsets(self, adsetids):
        """
        Method that takes a list of ad set ids and enables the audience network
        placement on them. Please note that this method does not perform any
        pre-validation check to see whether the ad set passed  satisfies the
        pre-requisites to have audience network enabled.

        Args:
            adsetids: List of ad set ids on which you want audience network
            enabled. Even if you have just one id, pass it as a list.
        Returns:
            A list of 'ad set id' vs. 'status' mapping with a further 'message'
            node whenever there was a failure to update the audience network.
            Returns an empty list when an empty list or non list element is
            passed.

            status 1 is a success.
            status 0 is a failure.

            Sample response format:
            [
                {'<ad_set_id_1>': {'status': 1}},
                {'<ad_set_id_2>': {'status': 0, 'message': '<exception_msg>'}},
                ...
            ]
        """
        results = []

        # check if adsets is a list
        if type(adsetids) is not list:
            return results

        # go over the list of adset ids
        for adsetid in adsetids:
            try:
                # read ad set info
                adset = AdSet(fbid=adsetid)
                adsetobj = adset.remote_read(fields=[AdSet.Field.targeting])

                # edit targeting spec info for placements
                targetinginfo = copy.deepcopy(adsetobj[AdSet.Field.targeting])
                targetinginfo[Targeting.Field.publisher_platforms]. \
                    append('audience_network')

                # update ad set info
                adset.update({AdSet.Field.targeting: targetinginfo})
                adset.remote_update()

                # update result list along with status
                results.append({adsetid: {'status': 1}})

            except FacebookError as e:

                # update result list along with status & message
                results.append({adsetid: {'status': 0, 'message': e.message}})

        return results
Ejemplo n.º 3
0
def retrieve_origin_adset_params(origin_adset_id):
    origin_adset = AdSet(fbid=origin_adset_id)
    origin_adset_params = origin_adset.remote_read(fields=FIELDS)
    return origin_adset_params
templatefolder = r"/THE TEMPLATE/"
excelfile = "ReachEstimateTemplatev2.xlsx"
templatefilepath = "".join([script_fp, templatefolder, excelfile])

export_wb = load_workbook(templatefilepath)
export_ws = export_wb['Reach']

r = 2
while sheet.cell(row=r, column=13).value != None:
    adset_id = str(sheet.cell(row=r, column=13).value).replace("c:", "")

    r += 1
    adset = AdSet(adset_id)

    #Pulls Adset Name
    AdsetDetail = adset.remote_read(fields=[AdSet.Field.name])
    AdsetDetailName = AdsetDetail["name"]

    #Pulls The Reach estimate for each adset
    reach_estimate = deliveryestimate.DeliveryEstimate.get_delivery_estimate(
        adset)
    TotalReach = reach_estimate[0]["estimate_mau"]

    export_ws.cell(row=r - 1, column=1).value = AdsetDetailName
    export_ws.cell(row=r - 1, column=2).value = int(TotalReach)
    export_ws.cell(row=r - 1, column=3).value = adset_id
    print("Processed row {}".format(r - 2))

print("\n\nProcessed all adsets!\n\n")

filetime = time.strftime("%Y%m%d-%H%M%S")
Ejemplo n.º 5
0
 def readAdSet(adset_id):
     ad_set = AdSet(fbid=adset_id)
     ad_set.remote_read(fields=[AdSet.Field.id])
     return ad_set
 def get_adset_features(self):
     adset = AdSet(self.adset_id)
     adsets = adset.remote_read(fields=list(adset_field.values()))
     for k in list(adsets.keys()):
         self.adset_features.update({k: adsets.get(k)})
     return self.adset_features