AdSets api 呼叫 Facebook
AdSets api call Facebook
我正在使用来自 Facebook 的 Java SDK 进行营销 API。我在阅读见解时遇到问题。我调用我帐户的广告集,并为每个广告集调用 getInsights() 函数。在对两个不同广告集的见解请求之间,我有一个 Thread.sleep(5000)。但是,我仍然收到错误 17:"User request limit reached"。我使用这个代码:
public static final APIContext context = new APIContext(
"ACCESS TOKEN",
"SECRET KEY"
);
public static void main(String[] args) throws APIException, ParseException
{
String sDate1="2018-04-01";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
String finala="2018-07-16";
Date datefinal=new SimpleDateFormat("yyyy-MM-dd").parse(finala);
System.out.println(datefinal);
c.setTime(df.parse(sDate1));
sDate1=df.format(c.getTime());
System.out.println(c.getTime());
while(!datefinal.before(c.getTime())) {
System.out.println(df.format(c.getTime()));
try {
AdAccount account = new AdAccount("ACCOUNT ID", context);
try {
APINodeList<AdSet> adsets = account.getAdSets().setTimeRange("{\"since\":\""+sDate1+"\",\"until\":\""+sDate1+"\"}").requestAllFields().execute();
adsets = adsets.withAutoPaginationIterator(true);
for(AdSet adset : adsets) {
System.out.println(adset.getFieldName());
Thread.sleep(5000);
//System.out.println(adset.getFieldId());
APINodeList<AdsInsights> adsInsightss = adset.getInsights()
.setTimeRange("{\"since\":\""+sDate1+"\",\"until\":\""+sDate1+"\"}")
.requestField("campaign_name")
.requestField("clicks")
.requestField("cpc")
.requestField("cpm")
.requestField("cpp")
.requestField("ctr")
.requestField("date_start")
.requestField("date_stop")
.requestField("frequency")
.requestField("impressions")
.requestField("reach")
.requestField("spend")
.requestField("unique_clicks")
.requestField("unique_ctr")
.requestField("website_ctr")
.requestField("website_purchase_roas")
.execute();
if(adsInsightss.size()>0) {
System.out.println(adset.getFieldName());
}
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
c.setTime(df.parse(sDate1));
c.add(Calendar.DATE, 1);
sDate1=df.format(c.getTime());
}
}
我只想获取在我指定的日期范围内至少有一次展示的广告组。或者至少在一个电话中获得所有见解。
谢谢!
我通过将 try 块中的代码替换为 :
解决了这个问题
APINodeList<AdsInsights> adsInsightss = account.getInsights().setTimeRange("{\"since\":\""+sDate1+"\",\"until\":\""+sDate1+"\"}").setParam("level", "ad").setParam("limit", 1000).requestField("adset_name")
.requestField("campaign_name")
.requestField("clicks")
.requestField("cpc")
.requestField("cpm")
.requestField("cpp")
.requestField("ctr")
.requestField("date_start")
.requestField("date_stop")
.requestField("frequency")
.requestField("impressions")
.requestField("reach")
.requestField("spend")
.requestField("unique_clicks")
.requestField("unique_ctr")
.requestField("website_ctr")
.requestField("website_purchase_roas")
.requestField("action_values").execute();
我正在使用来自 Facebook 的 Java SDK 进行营销 API。我在阅读见解时遇到问题。我调用我帐户的广告集,并为每个广告集调用 getInsights() 函数。在对两个不同广告集的见解请求之间,我有一个 Thread.sleep(5000)。但是,我仍然收到错误 17:"User request limit reached"。我使用这个代码:
public static final APIContext context = new APIContext(
"ACCESS TOKEN",
"SECRET KEY"
);
public static void main(String[] args) throws APIException, ParseException
{
String sDate1="2018-04-01";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
String finala="2018-07-16";
Date datefinal=new SimpleDateFormat("yyyy-MM-dd").parse(finala);
System.out.println(datefinal);
c.setTime(df.parse(sDate1));
sDate1=df.format(c.getTime());
System.out.println(c.getTime());
while(!datefinal.before(c.getTime())) {
System.out.println(df.format(c.getTime()));
try {
AdAccount account = new AdAccount("ACCOUNT ID", context);
try {
APINodeList<AdSet> adsets = account.getAdSets().setTimeRange("{\"since\":\""+sDate1+"\",\"until\":\""+sDate1+"\"}").requestAllFields().execute();
adsets = adsets.withAutoPaginationIterator(true);
for(AdSet adset : adsets) {
System.out.println(adset.getFieldName());
Thread.sleep(5000);
//System.out.println(adset.getFieldId());
APINodeList<AdsInsights> adsInsightss = adset.getInsights()
.setTimeRange("{\"since\":\""+sDate1+"\",\"until\":\""+sDate1+"\"}")
.requestField("campaign_name")
.requestField("clicks")
.requestField("cpc")
.requestField("cpm")
.requestField("cpp")
.requestField("ctr")
.requestField("date_start")
.requestField("date_stop")
.requestField("frequency")
.requestField("impressions")
.requestField("reach")
.requestField("spend")
.requestField("unique_clicks")
.requestField("unique_ctr")
.requestField("website_ctr")
.requestField("website_purchase_roas")
.execute();
if(adsInsightss.size()>0) {
System.out.println(adset.getFieldName());
}
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
c.setTime(df.parse(sDate1));
c.add(Calendar.DATE, 1);
sDate1=df.format(c.getTime());
}
}
我只想获取在我指定的日期范围内至少有一次展示的广告组。或者至少在一个电话中获得所有见解。 谢谢!
我通过将 try 块中的代码替换为 :
解决了这个问题APINodeList<AdsInsights> adsInsightss = account.getInsights().setTimeRange("{\"since\":\""+sDate1+"\",\"until\":\""+sDate1+"\"}").setParam("level", "ad").setParam("limit", 1000).requestField("adset_name")
.requestField("campaign_name")
.requestField("clicks")
.requestField("cpc")
.requestField("cpm")
.requestField("cpp")
.requestField("ctr")
.requestField("date_start")
.requestField("date_stop")
.requestField("frequency")
.requestField("impressions")
.requestField("reach")
.requestField("spend")
.requestField("unique_clicks")
.requestField("unique_ctr")
.requestField("website_ctr")
.requestField("website_purchase_roas")
.requestField("action_values").execute();