You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ADFORM API PHP指标问题:新手求助设置adUniqueness参数

Adjusting adUniqueness for Adform Reporting API Requests

Hey there! Since you're new to PHP and working with APIs, let’s walk through how to tweak the adUniqueness parameter for your Adform reporting request—super straightforward once you know where to put it.

The Core Issue

Right now, the API is falling back to the default adUniqueness: "all" value because you aren’t explicitly setting it in your POST request body. To get the specific uniqueness metrics you want, you need to include this parameter directly in the JSON payload you send to the endpoint.

Step-by-Step Implementation

First, make sure you have all the required pieces: your authentication token, date range, dimensions, and metrics. Then add the adUniqueness parameter with your desired value (like user, session, or device—whichever matches your reporting needs).

Example with cURL (PHP)

This is a common approach for beginners since it’s built into PHP:

<?php
// Adform API endpoint
$apiUrl = 'https://api.adform.com/v1/reportingstats/agency/reportdata';

// Replace with your actual authentication token
$authToken = 'YOUR_ADFORM_BEARER_TOKEN';

// Build your request payload with adUniqueness included
$requestPayload = [
    'dateRange' => [
        'startDate' => '2024-02-01',
        'endDate' => '2024-02-29'
    ],
    'dimensions' => ['campaignName', 'adId'],
    'metrics' => ['impressions', 'uniqueImpressions'],
    // Set your desired adUniqueness value here
    'adUniqueness' => 'user'
];

// Initialize cURL session
$curl = curl_init($apiUrl);

// Configure cURL options
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($requestPayload));
curl_setopt($curl, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $authToken,
    'Content-Type: application/json'
]);

// Execute request and get response
$response = curl_exec($curl);
$httpStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

// Clean up cURL session
curl_close($curl);

// Handle response
if ($httpStatusCode === 200) {
    $reportData = json_decode($response, true);
    print_r($reportData);
} else {
    echo "Request failed with status code: $httpStatusCode\n";
    echo "Error details: $response";
}
?>

Example with Guzzle (PHP)

If you’re using a framework or prefer a more modern HTTP client, Guzzle works great:

<?php
require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client();
$authToken = 'YOUR_ADFORM_BEARER_TOKEN';

try {
    $response = $client->post('https://api.adform.com/v1/reportingstats/agency/reportdata', [
        'headers' => [
            'Authorization' => 'Bearer ' . $authToken,
            'Content-Type' => 'application/json',
        ],
        'json' => [
            'dateRange' => [
                'startDate' => '2024-02-01',
                'endDate' => '2024-02-29'
            ],
            'dimensions' => ['campaignId'],
            'metrics' => ['uniqueClicks'],
            'adUniqueness' => 'session' // Your chosen value here
        ]
    ]);

    $reportData = json_decode($response->getBody(), true);
    print_r($reportData);
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    echo "Error: " . $e->getMessage();
}
?>

Key Notes to Remember

  • Match metrics to adUniqueness: Some metrics (like uniqueImpressions) rely on this parameter to calculate correctly, so ensure your value aligns with what you’re trying to measure.
  • Test first with tools: Before writing PHP code, use tools like Postman or Insomnia to send a test POST request with your desired adUniqueness value. This helps you confirm the request works before translating it to PHP.
  • Check error codes: If you get a 400 error, double-check your payload syntax. 401 means your auth token is invalid, and 403 means you don’t have permission for the requested data.

内容的提问来源于stack exchange,提问作者user774952

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:54:37