Hi Team,


we are getting the Report from dfp using custom fields for past 3 months.


Today while running the same class we got below error,


Exception in thread "main" java.lang.IllegalStateException: Report 
11240782934 must be completed before downloading. It is currently: 
IN_PROGRESS
at com.google.common.base.Preconditions.checkState(Preconditions.java:444)
at 
com.google.api.ads.admanager.axis.utils.v201811.ReportDownloader.getDownloadUrl(ReportDownloader.java:181)
at 
banner.RunReportWithCustomFields.runExample(RunReportWithCustomFields.java:120)
at 
banner.RunReportWithCustomFields.createCredentialAndDfSession(RunReportWithCustomFields.java:166)
at banner.RunReportWithCustomFields.main(RunReportWithCustomFields.java:205)


my class file is:


public class RunReportWithCustomFields {
//static boolean downloadstatus = false;

private static class RunReportWithCustomFieldsParams extends 
CodeSampleParams {
@parameter <https://github.com/parameter>(names = 
ArgumentNames.CUSTOM_FIELD_ID, required = true, description = "The ID of 
the custom field to include in the report.")
// private long[] customFieldId_HC = new long[3];//info:have to change the 
length when new column is added in DFP
private long[] customFieldId_CUG = new long[2];//info:have to change the 
length when new column is added in DFP
}

/**

   - Runs the example.
   - 
   - @param <https://github.com/param> adManagerServices
   - 
   
          the services factory.
   
   - @param <https://github.com/param> session
   - 
   
          the session.
   
   - @param <https://github.com/param> customFieldId
   - 
   
          the ID of the custom field to include in the report.
   
   - @throws <https://github.com/throws> ApiException
   - 
   
           if the API request failed with one or more service errors.
   
   - @throws <https://github.com/throws> RemoteException
   - 
   
           if the API request failed due to other errors.
   
   - @throws <https://github.com/throws> IOException
   - 
   
           if unable to write the response to a file.
   
   - @throws <https://github.com/throws> InterruptedException
   - 
   
           if the thread is interrupted while waiting for the report to
   
   - 
   
           complete.
   
   
*/
public static void runExample(AdManagerServices adManagerServices, 
AdManagerSession session,String downloadFileName, long[] customFieldId) 
throws IOException, InterruptedException {
// Get the ReportService.
ReportServiceInterface reportService = adManagerServices.get(session, 
ReportServiceInterface.class);

// Create report query.
ReportQuery reportQuery = new ReportQuery();
reportQuery.setDimensions(new Dimension[] { Dimension.DATE, Dimension.ORDER_ID, 
Dimension.LINE_ITEM_ID, Dimension.LINE_ITEM_NAME });
reportQuery.setColumns(new Column[] { Column.AD_SERVER_IMPRESSIONS, 
Column.AD_SERVER_CLICKS, Column.AD_SERVER_CTR});
reportQuery.setDimensionAttributes(new DimensionAttribute[] { 
DimensionAttribute.LINE_ITEM_START_DATE_TIME,DimensionAttribute.LINE_ITEM_END_DATE_TIME});
// Set the dynamic date range type or a custom start and end date.

// reportQuery.setDateRangeType(DateRangeType.YESTERDAY);
// reportQuery.setDateRangeType(DateRangeType.LAST_3_MONTHS);
// reportQuery.setDateRangeType(DateRangeType.CUSTOM_DATE);
// reportQuery.setStartDate(DateTimes.toDateTime("2018-10-01T00:00:00",
// "America/New_York").getDate());
// reportQuery.setEndDate(DateTimes.toDateTime("2019-04-29T00:00:00",
// "America/New_York").getDate());
reportQuery.setDateRangeType(DateRangeType.TODAY);

// Set the custom field IDs.
reportQuery.setCustomFieldIds(customFieldId);
// Create report job.
ReportJob reportJob = new ReportJob();
reportJob.setReportQuery(reportQuery);

// Run report job.
reportJob = reportService.runReportJob(reportJob);
System.out.println(reportJob+" reportJob");
// Create report downloader.
ReportDownloader reportDownloader = new ReportDownloader(reportService, 
reportJob.getId());

// Wait for the report to be ready.
reportDownloader.waitForReportReady();
System.out.println(downloadFileName+" file Downloading started ...");
// Change to your file location.
File file = File.createTempFile(downloadFileName, ".csv.gz", new 
File(BannerConstants.CSV_FILE_DOWNLOAD_PATH));

System.out.println("Downloading report to %s ..." + file.toString());

// Download the report.
ReportDownloadOptions options = new ReportDownloadOptions();
options.setExportFormat(ExportFormat.CSV_DUMP);
options.setUseGzipCompression(true);
URL url = reportDownloader.getDownloadUrl(options);
Resources.asByteSource(url).copyTo(Files.asByteSink(file));
System.out.println(downloadFileName+" file downloading done.");

// downloadstatus = true;
}

public static long[] setParams(String[] args,String[] 
customFieldIds,Boolean accountTypeIsCUG){
RunReportWithCustomFieldsParams params = new 
RunReportWithCustomFieldsParams();
long[] assignedParams = new long[customFieldIds.length];
if (!params.parseArguments(args)) {
// Either pass the required parameters for this example on the
// command line, or insert them
// into the code here. See the parameter class definition above for
// descriptions.
// for(int i = 0;i < customFieldIds.length;i++){
for (int i = 0; i < customFieldIds.length; i++) {
if(accountTypeIsCUG){
params.customFieldId_CUG[i] = Long.parseLong(customFieldIds[i]);
assignedParams[i] = params.customFieldId_CUG[i];
}else{
// params.customFieldId_HC[i] = Long.parseLong(customFieldIds[i]);
// assignedParams[i] = params.customFieldId_HC[i];
}
}
}
return assignedParams;
}

public static void createCredentialAndDfSession(String 
credentialPath,String applicationName,String networkCode,String 
downloadFileName,long[] dfpParams){
AdManagerSession session;
try {
// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential = new 
OfflineCredentials.Builder().forApi(Api.AD_MANAGER).withJsonKeyFilePath(credentialPath).build().generateCredential();
// Construct a DfpSession.
session = new 
AdManagerSession.Builder().withApplicationName(applicationName).withNetworkCode(networkCode).withOAuth2Credential(oAuth2Credential).build();
} catch (ValidationException ve) {
System.err.printf("REQUEST_FAILED configuration in the %s file. Exception: 
%s%n", DEFAULT_CONFIGURATION_FILENAME, ve);
return;
} catch (OAuthException oe) {
System.err.printf("REQUEST_FAILED to create OAuth credentials. Check OAuth 
settings in the %s file. " + "Exception: %s%n", 
DEFAULT_CONFIGURATION_FILENAME, oe);
return;
}
AdManagerServices adManagerServices = new AdManagerServices();
try {
runExample(adManagerServices, session,downloadFileName ,dfpParams);
} catch (ApiException apiException) {
// ApiException is the base class for most exceptions thrown by an
// API request. Instances
// of this exception have a message and a collection of ApiErrors
// that indicate the
// type and underlying cause of the exception. Every exception
// object in the admanager.axis
// packages will return a meaningful value from toString
//
// ApiException extends RemoteException, so this catch block must
// appear before the
// catch block for RemoteException.
System.err.println("REQUEST_FAILED due to ApiException. Underlying 
ApiErrors:");
if (apiException.getErrors() != null) {
int i = 0;
for (ApiError apiError : apiException.getErrors()) {
System.err.printf(" Error %d: %s%n", i++, apiError);
}
}
} catch (RemoteException re) {
System.err.printf("REQUEST_FAILED unexpectedly due to RemoteException: 
%s%n", re);
} catch (IOException ioe) {
System.err.printf("REQUEST_FAILED due to IOException: %s%n", ioe);
} catch (InterruptedException ie) {
System.err.printf("REQUEST_FAILED Thread was interrupted: %s%n", ie);
}
}

public static void main(String[] args) {
BannerConstants BannerConstants = new BannerConstants();
//setting parameters and fetching stats from HC account
// long[] customParamsHe = 
setParams(args,BannerConstants.CUSTOMFIELDS_HE,false);
// 
createCredentialAndDfSession(BannerConstants.JSON_CREDENTIAL_PATH_HC,BannerConstants.APPLICATION_NAME,BannerConstants.NETWORK_CODE,BannerConstants.FILE_NAME_HC,customParamsHe);
// //setting parameters and fetching stats from CUG account
// if(downloadstatus){
// downloadstatus = false;
long[] customParamsCug = 
setParams(args,BannerConstants.CUSTOMFIELDS_CUG,true);
createCredentialAndDfSession(BannerConstants.JSON_CREDENTIAL_PATH_CUG,BannerConstants.APPLICATION_NAME_CUG,BannerConstants.NETWORK_CODE_CUG,BannerConstants.FILE_NAME_CUG,customParamsCug);
// }
// if(downloadstatus){
System.out.println("Sucessfully downloaded two files..!");
// }
}

}



Please help me on this as soon as possible, as this is priority for us.


Thanks in advance.

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/6b741f57-bcac-4584-ae9c-ace9124cb3c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to