googleads / googleads-java-lib

Google Ad Manager SOAP API Client Library for Java
Apache License 2.0
226 stars 360 forks source link

page.getResults is null #214

Closed MalikCheng closed 3 years ago

MalikCheng commented 4 years ago

Currently i am trying run AdManager reports API RunSavedQuery example .throw a Null Exception.

Exception in thread "main" java.lang.NullPointerException
    at java.util.Objects.requireNonNull(Objects.java:203)
    at java.util.Arrays$ArrayList.<init>(Arrays.java:3813)
    at java.util.Arrays.asList(Arrays.java:3800)
    at com.wps.education.utils.RunSavedQuery.runExample(RunSavedQuery.java:99)
    at com.wps.education.utils.RunSavedQuery.main(RunSavedQuery.java:179)

near 99 line

        // Create statement to retrieve the saved query.
        StatementBuilder statementBuilder =
                new StatementBuilder()
                        .where("id = :id")
                        .orderBy("id ASC")
                        .limit(1)
                        .withBindVariableValue("id", savedQueryId);

        SavedQueryPage page = reportService.getSavedQueriesByStatement(statementBuilder.toStatement());
        SavedQuery savedQuery = Iterables.getOnlyElement(Arrays.asList(page.getResults())); // line 99

        if (!savedQuery.getIsCompatibleWithApiVersion()) {
            throw new IllegalStateException("The saved query is not compatible with this API version.");
        }

Debug found the page.getResults() is null on the line 99. pom :

        <dependency>
            <groupId>com.google.api-ads</groupId>
            <artifactId>ads-lib</artifactId>
            <version>RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.google.api-ads</groupId>
            <artifactId>dfp-axis</artifactId>
            <version>RELEASE</version>
        </dependency>

I set savedQueryId is 11772918516 in the https://www.google.com/admanager/21xxx76111#reports/report/detail/report_id=1177xx

I can see the result from the https://www.google.com/admanager/21xxx76111#reports/report/detail/report_id=1177xx url when click on run
button on the web UI.

Did I set it up wrong?

christopherseeley commented 4 years ago

This typically happens when you're authenticating as a service account and haven't shared the saved query with that Ad Manager user. Is that the case?

More common reporting issues are listed in this FAQ: https://developers.google.com/ad-manager/api/reporting#faq

MalikCheng commented 4 years ago

Thank for your reply. I check that service account is an administrator,but it didn't work. I try to add service account into modifier item on setting report page , it work !

useful link https://groups.google.com/g/google-doubleclick-for-publishers-api