Set Up Your Application
Stay organized with collections
Save and categorize content based on your preferences.
Before you can make requests to the API, you must set up authorization. If you are using a client library, you must also create a Service
object.
The following code demonstrates how to configure your client and authorize requests using an API key.
Java
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.adexperiencereport.v1.AdExperienceReport;
import com.google.api.services.adexperiencereport.v1.AdExperienceReportRequestInitializer;
import com.google.api.services.adexperiencereport.v1.model.SiteSummaryResponse;
import com.google.api.services.adexperiencereport.v1.model.ViolatingSitesResponse;
...
public static void main(String[] args) {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
AdExperienceReportRequestInitializer reqInitializer =
new AdExperienceReportRequestInitializer("YOUR_API_KEY");
AdExperienceReport service = new AdExperienceReport.Builder(httpTransport, jsonFactory, null)
.setAdExperienceReportRequestInitializer(reqInitializer)
.setApplicationName("YOUR_APPLICATION_NAME")
.build();
ViolatingSitesResponse response = service.violatingSites().list().execute();
...
}
...
Python
from apiclient.discovery import build
api_key = 'YOUR_API_KEY'
service = build('adexperiencereport', 'v1', developerKey=api_key)
response = service.violatingSites().list().execute()
...
PHP
$client = new Google_Client();
$client->setApplicationName("YOUR_APPLICATION_NAME");
$client->setDeveloperKey("YOUR_API_KEY");
$service = new Google_Service_AdExperienceReport($client);
$response = $service->violatingSites;
...
.NET
using Google.Apis.AdExperienceReport.v1.AdExperienceReportService;
using Google.Apis.Services.BaseClientService.Initializer;
...
public static void Main(string[] args)
{
var service = new AdExperienceReportService(new BaseClientService.Initializer
{
ApplicationName = "YOUR_APPLICATION_NAME",
ApiKey = "YOUR_API_KEY",
});
var response = await service.ViolatingSites.List().ExecuteAsync();
...
}
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-28 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[[["\u003cp\u003eBefore making API requests, ensure you have set up authorization, potentially by implementing an API key.\u003c/p\u003e\n"],["\u003cp\u003eWhen utilizing client libraries, a \u003ccode\u003eService\u003c/code\u003e object needs to be created.\u003c/p\u003e\n"],["\u003cp\u003eProvided code samples demonstrate configuration and request authorization across Java, Python, PHP, and .NET.\u003c/p\u003e\n"],["\u003cp\u003eAll code examples showcase using an API key for authentication and making a basic request to the Ad Experience Report API.\u003c/p\u003e\n"]]],["API requests require prior authorization and, when using client libraries, the creation of a `Service` object. Client configuration involves setting up an API key, which is demonstrated in Java, Python, PHP, and .NET. Java initializes `HttpTransport`, `JacksonFactory`, and `AdExperienceReportRequestInitializer`. Python and PHP directly use their client library to set an API key. .NET utilizes `BaseClientService.Initializer` to set the API key and application name. All languages then use their `service` to obtain a response.\n"],null,["# Set Up Your Application\n\nBefore you can make requests to the API, you must set up [authorization](/ad-experience-report/v1/how-tos/authorizing). If you are using a [client library](/ad-experience-report/v1/libraries), you must also create a `Service` object.\n\nThe following code demonstrates how to configure your client and authorize requests using an API key. \n\nJava\n----\n\n```java\nimport com.google.api.client.http.HttpTransport;\nimport com.google.api.client.http.javanet.NetHttpTransport;\nimport com.google.api.client.json.jackson.JacksonFactory;\n\nimport com.google.api.services.adexperiencereport.v1.AdExperienceReport;\nimport com.google.api.services.adexperiencereport.v1.AdExperienceReportRequestInitializer;\n\nimport com.google.api.services.adexperiencereport.v1.model.SiteSummaryResponse;\nimport com.google.api.services.adexperiencereport.v1.model.ViolatingSitesResponse;\n...\n\n public static void main(String[] args) {\n HttpTransport httpTransport = new NetHttpTransport();\n JacksonFactory jsonFactory = new JacksonFactory();\n AdExperienceReportRequestInitializer reqInitializer =\n new AdExperienceReportRequestInitializer(\"\u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e\");\n\n AdExperienceReport service = new AdExperienceReport.Builder(httpTransport, jsonFactory, null)\n .setAdExperienceReportRequestInitializer(reqInitializer)\n .setApplicationName(\"\u003cvar translate=\"no\"\u003eYOUR_APPLICATION_NAME\u003c/var\u003e\")\n .build();\n\n ViolatingSitesResponse response = service.violatingSites().list().execute();\n ...\n }\n...\n```\n\nPython\n------\n\n```python\nfrom apiclient.discovery import build\n\napi_key = '\u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e'\nservice = build('adexperiencereport', 'v1', developerKey=api_key)\n\nresponse = service.violatingSites().list().execute()\n...\n```\n\nPHP\n---\n\n```php\n$client = new Google_Client();\n$client-\u003esetApplicationName(\"\u003cvar translate=\"no\"\u003eYOUR_APPLICATION_NAME\u003c/var\u003e\");\n$client-\u003esetDeveloperKey(\"\u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e\");\n$service = new Google_Service_AdExperienceReport($client);\n\n$response = $service-\u003eviolatingSites;\n...\n```\n\n.NET\n----\n\n```gdscript\nusing Google.Apis.AdExperienceReport.v1.AdExperienceReportService;\nusing Google.Apis.Services.BaseClientService.Initializer;\n...\n\n public static void Main(string[] args)\n {\n var service = new AdExperienceReportService(new BaseClientService.Initializer\n {\n ApplicationName = \"\u003cvar translate=\"no\"\u003eYOUR_APPLICATION_NAME\u003c/var\u003e\",\n ApiKey = \"\u003cvar translate=\"no\"\u003eYOUR_API_KEY\u003c/var\u003e\",\n });\n\n var response = await service.ViolatingSites.List().ExecuteAsync();\n ...\n }\n```"]]