Java 内部服务器错误,作为获取广告分页时Facebook Graph API的响应

Java 内部服务器错误,作为获取广告分页时Facebook Graph API的响应,java,facebook,facebook-graph-api,facebook-ads-api,Java,Facebook,Facebook Graph Api,Facebook Ads Api,一段时间以来,我们一直收到来自ads端点的奇怪错误响应消息“Internal Server error” 为了简单起见,我们正在开发一个应用程序,该应用程序利用了“Facebook图形API”,它可以将不同级别的数据从Facebook界面拉到我们的数据库。虽然我们能够获取活动级别的信息,但现在的问题是“我们无法获取广告级别的信息”。它不断抛出一个错误“内部服务器错误” 这一问题在过去仅限于一个特定账户,但现在,这涉及所有账户 错误响应 response = (okhttp3.Response)

一段时间以来,我们一直收到来自ads端点的奇怪错误响应消息“Internal Server error”

为了简单起见,我们正在开发一个应用程序,该应用程序利用了“Facebook图形API”,它可以将不同级别的数据从Facebook界面拉到我们的数据库。虽然我们能够获取活动级别的信息,但现在的问题是“我们无法获取广告级别的信息”。它不断抛出一个错误“内部服务器错误”

这一问题在过去仅限于一个特定账户,但现在,这涉及所有账户

错误响应

response = (okhttp3.Response) Response{protocol=http/1.1, code=500, message=Internal Server Error, url=https://graph.facebook.com/v3.3/act_id/ads?access_token=MY_ACCESS_TOKEN&fields=%5B%22account_id%22%2C%22campaign_id%22%2C%22adset_id%22%2C%22id%22%2C%22bid_amount%22%2C%22
name%22%2C%22status%22%2C%22preview_shareable_link%22%5D&limit=25&
after=QVFIUkFzZAVdONXEwMXc5NjlOWURwczRQN0V3QW12NndRa0I4ZAUxsSjNkZA0FTRHR1U1dnaTQ5MTh2QnJ3bzNwWkNPd21jbC1tbjRmZAF81WVBsc0txaERCMHVn}
下面的代码在前面的几个帐户中运行良好。但是,同样的,现在给出上述指定的错误消息

获取广告信息的代码

public List facebookAdsSynchThroughJson(String accessTokens, Long advertAccId, Properties googleStructureProperties, byte isOnScheduler, String appSecret) {
        this.access_tokens = accessTokens;
        this.appSecret = appSecret;
        APIContext context = new APIContext(accessTokens, appSecret).enableDebug(true);
        List<FacebookAdsStructure> adsList = new ArrayList<>();
        String ads = "";
        JSONObject advertIdObj = null;
        JSONArray dataList = null;
        ObjectMapper mapper = null;
        boolean cond = true;
        boolean success = false;
        int limitValue = 100;
        try {
            while (cond) {
                try {
                    AdAccount adAccount = new AdAccount(advertAccId, context).get().execute();
                    List adsFields = new ArrayList();
                    adsFields.add("account_id");
                    adsFields.add("campaign_id");
                    adsFields.add("adset_id");
                    adsFields.add("id");
                    adsFields.add("bid_amount");
                    adsFields.add("name");
                    adsFields.add("status");
                    adsFields.add("preview_shareable_link");
                    Map<String, Object> adsmap = new HashMap<>();
                    adsmap.put("fields", adsFields);
                    adsmap.put("limit", limitValue);
                    ads = adAccount.getAds().setParams(adsmap).execute().getRawResponseAsJsonObject().toString();
                } catch (APIException ex) {
                    LOGGER.info("Exception thrown when fetching ads for Account Id: " + advertAccId + " with limit value: " + limitValue);
                    LOGGER.error(ex);
                    if (limitValue > 6) {
                        cond = true;
                        limitValue = limitValue / 2;
                    } else {
                        cond = false;
                        success = false;
                        break;
                    }
                }
                if (!ads.isEmpty()) {
                    cond = false;
                    success = true;
                }
            }
            if (success) {
                advertIdObj = new JSONObject(ads);
                dataList = advertIdObj.getJSONArray("data");
                mapper = new ObjectMapper();
                adsList = mapper.readValue(dataList.toString(), new TypeReference<List<FacebookAdsStructure>>() {
                });
                JsonObject obj;
                JsonParser parser = new JsonParser();
                JsonElement result = parser.parse(ads);
                obj = result.getAsJsonObject();
                int maxTries = 1;
                if (obj.has("data") && maxTries <= 5) {
                    while (obj.has("paging") && maxTries <= 5) {
                        JsonObject paging = obj.get("paging").getAsJsonObject();
                        if (paging.has("cursors")) {
                            JsonObject cursors = paging.get("cursors").getAsJsonObject();
                            String before = cursors.has("before") ? cursors.get("before").getAsString() : null;
                            String after = cursors.has("after") ? cursors.get("after").getAsString() : null;
                        }
                        String previous = paging.has("previous") ? paging.get("previous").getAsString() : null;
                        String next = paging.has("next") ? paging.get("next").getAsString() : "empty";
                        if (!next.equalsIgnoreCase("empty")) {
                            OkHttpClient client = new OkHttpClient.Builder()
                                    .connectTimeout(5, TimeUnit.MINUTES)
                                    .writeTimeout(5, TimeUnit.MINUTES)
                                    .readTimeout(5, TimeUnit.MINUTES)
                                    .build();
                            Request request1 = new Request.Builder().url(next).get().build();
                            Response response = client.newCall(request1).execute();
                            if (response.isSuccessful()) {
                                maxTries = 1;
                                ads = response.body().string();
                                advertIdObj = new JSONObject(ads);
                                dataList = advertIdObj.getJSONArray("data");
                                mapper = new ObjectMapper();
                                List<FacebookAdsStructure> adsLists = new ArrayList<>();
                                adsLists = mapper.readValue(dataList.toString(), new TypeReference<List<FacebookAdsStructure>>() {
                                });
                                adsList.addAll(adsLists);
                                LOGGER.info("Fetched the Ad Structure.." + adsList.size());
                                parser = new JsonParser();
                                result = parser.parse(ads);
                                obj = result.getAsJsonObject();
                            } else {
                                LOGGER.info("Exception in response when fetching ads for Account Id: " + advertAccId + " , error response message: " + response.message() + " and with limit value: " + limitValue);
                                maxTries++;
                                if (maxTries >= 6) {
                                    break;
                                }
                                try {
                                    LOGGER.info("Thread Sleeping For 2 Minutes - Started for fb se_account_id " + advertAccId + " and maxTries = " + maxTries);
                                    Thread.sleep(120000);
                                    LOGGER.info("Thread Sleeping For 2 Minutes - Completed for fb se_account_id " + advertAccId + " and maxTries = " + maxTries);
                                } catch (InterruptedException ex) {
                                    Logger.getLogger(FacebookAccountStructureSyncThroughJson.class.getName()).log(Level.SEVERE, null, ex);
                                }
                            }
                        } else {
                            obj = new JsonObject();
                        }
                    }
                }
            }
        } catch (JsonSyntaxException | IOException | JSONException ex) {
            LOGGER.error(ex);
        }
        return adsList;
    }
public List facebookadsynchthroughjson(字符串accessTokens、长advertAccId、属性googleStructureProperties、字节isOnScheduler、字符串appSecret){
this.access\u tokens=accessTokens;
this.appSecret=appSecret;
APIContext context=新的APIContext(accessTokens,appSecret).enableDebug(true);
List adsList=new ArrayList();
字符串广告=”;
JSONObject广告对象=null;
JSONArray dataList=null;
ObjectMapper映射器=null;
布尔cond=true;
布尔成功=假;
int limitValue=100;
试一试{
while(cond){
试一试{
AdAccount AdAccount=new AdAccount(advertAccId,context).get().execute();
List adsFields=new ArrayList();
添加(“账户id”);
添加(“活动id”);
adsFields.add(“adset_id”);
添加(“id”);
添加(“投标金额”);
添加(“名称”);
添加(“状态”);
添加(“预览共享链接”);
Map adsmap=newhashmap();
adsmap.put(“字段”,adsFields);
adsmap.put(“limit”,limitValue);
ads=adAccount.getAds().setParams(adsmap).execute().getRawResponseAsJsonObject().toString();
}捕获(APIEX){
LOGGER.info(“获取帐户Id为“+advertAccId+”且限制值为“+limitValue”)的广告时引发异常);
记录器错误(ex);
如果(限制值>6){
cond=真;
limitValue=limitValue/2;
}否则{
cond=假;
成功=错误;
打破
}
}
如果(!ads.isEmpty()){
cond=假;
成功=真实;
}
}
如果(成功){
advertIdObj=新的JSONObject(ads);
dataList=advertIdObj.getJSONArray(“数据”);
映射器=新的ObjectMapper();
adsList=mapper.readValue(dataList.toString(),new-TypeReference()){
});
JsonObject对象;
JsonParser=新的JsonParser();
JsonElement result=parser.parse(ads);
obj=result.getAsJsonObject();
int max=1;

如果(对象有(“数据”)&&Maxtrys已经有一个类似问题的错误报告,如果您的案例明显不同,建议您加入该问题,或者创建自己的问题。@04FS facebook支持团队已经有一段时间没有更新该线程了。它是我们的拦路虎,因此将其发布在此处,以便有人可以帮助我。不知道如何帮助您你在这里-我们不能通过查看Facebook的系统来获得更多关于错误的信息。除非有人碰巧遇到这个人,他经历了同样的错误,并且偶然发现了一个解决方案…