1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
3
+ *
4
+ * You are hereby granted a non-exclusive, worldwide, royalty-free license to
5
+ * use, copy, modify, and distribute this software in source code or binary
6
+ * form for use in connection with the web services and APIs provided by
7
+ * Facebook.
8
+ *
9
+ * As with any software that integrates with the Facebook platform, your use
10
+ * of this software is subject to the Facebook Developer Principles and
11
+ * Policies [http://developers.facebook.com/policy/]. This copyright notice
12
+ * shall be included in all copies or substantial portions of the software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
+ * DEALINGS IN THE SOFTWARE.
21
+ *
22
+ */
23
+
24
+ import com .facebook .ads .sdk .*;
25
+ import java .io .File ;
26
+ import java .util .Arrays ;
27
+
28
+ public class AdAccountAdSetsPostInterestTargeting {
29
+ public static void main (String args []) throws APIException {
30
+
31
+ String access_token = "<ACCESS_TOKEN>" ;
32
+ String app_secret = "<APP_SECRET>" ;
33
+ String app_id = "<APP_ID>" ;
34
+ String id = "<AD_ACCOUNT_ID>" ;
35
+ APIContext context = new APIContext (access_token ).enableDebug (true );
36
+
37
+ new AdAccount (id , context ).createAdSet ()
38
+ .setName ("My First AdSet" )
39
+ .setDailyBudget (10000L )
40
+ .setBidAmount (300L )
41
+ .setBillingEvent (AdSet .EnumBillingEvent .VALUE_IMPRESSIONS )
42
+ .setOptimizationGoal (AdSet .EnumOptimizationGoal .VALUE_REACH )
43
+ .setCampaignId ("<adCampaignLinkClicksID>" )
44
+ .setPromotedObject ("{\" page_id\" :\" <pageID>\" }" )
45
+ .setTargeting (
46
+ new Targeting ()
47
+ .setFieldAgeMax (24L )
48
+ .setFieldAgeMin (20L )
49
+ .setFieldDevicePlatforms (Arrays .asList (Targeting .EnumDevicePlatforms .VALUE_MOBILE ))
50
+ .setFieldFlexibleSpec (Arrays .asList (
51
+ new FlexibleTargeting ()
52
+ .setFieldInterests (Arrays .asList (
53
+ new IDName ()
54
+ .setFieldId ("<adsInterestID>" )
55
+ .setFieldName ("<adsInterestName>" )
56
+ ))
57
+ ))
58
+ .setFieldGenders (Arrays .asList (1L ))
59
+ .setFieldGeoLocations (
60
+ new TargetingGeoLocation ()
61
+ .setFieldCities (Arrays .asList (
62
+ new TargetingGeoLocationCity ()
63
+ .setFieldDistanceUnit ("mile" )
64
+ .setFieldKey (777934L )
65
+ .setFieldRadius (10L )
66
+ ))
67
+ .setFieldCountries (Arrays .asList ("US" ))
68
+ .setFieldRegions (Arrays .asList (
69
+ new TargetingGeoLocationRegion ()
70
+ .setFieldKey ("4081" )
71
+ ))
72
+ )
73
+ .setFieldPublisherPlatforms (Arrays .asList ("facebook" , "audience_network" ))
74
+ )
75
+ .setStatus (AdSet .EnumStatus .VALUE_PAUSED )
76
+ .execute ();
77
+
78
+ }
79
+ }
0 commit comments