使用Bing Ads API PHP报告请求,您可以轻松地获取与广告相关的数据,并无需手动下载报告。这个功能非常方便,特别是对于需要快速分析和处理大量数据的广告主和营销人员来说。下面是一个简单的案例代码,展示了如何使用Bing Ads API PHP报告请求来获取广告报告数据。
案例代码:phpuse Microsoft\BingAds\Auth\ServiceClientType;use Microsoft\BingAds\Auth\AuthorizationData;use Microsoft\BingAds\Auth\OAuthWebAuthCodeGrant;use Microsoft\BingAds\Auth\OAuthDesktopMobileAuthCodeGrant;use Microsoft\BingAds\Auth\OAuthRequestParameters;use Microsoft\BingAds\V13\Reporting\ReportRequest;use Microsoft\BingAds\V13\Reporting\ReportFormat;use Microsoft\BingAds\V13\Reporting\ReportAggregation;use Microsoft\BingAds\V13\Reporting\AccountPerformanceReportRequest;use Microsoft\BingAds\V13\Reporting\AccountPerformanceReportFilter;use Microsoft\BingAds\V13\Reporting\AccountPerformanceReportColumn;use Microsoft\BingAds\V13\Reporting\AccountPerformanceReportSort;use Microsoft\BingAds\V13\Reporting\ReportTime;use Microsoft\BingAds\V13\Reporting\DateRange;// 设置授权数据$authorizationData = new AuthorizationData();$authorizationData->Authentication = new OAuthDesktopMobileAuthCodeGrant();$authorizationData->Authentication->ClientId = 'YOUR_CLIENT_ID';$authorizationData->Authentication->ClientSecret = 'YOUR_CLIENT_SECRET';$authorizationData->Authentication->RedirectUri = 'YOUR_REDIRECT_URI';$authorizationData->Authentication->AuthorizationEndpoint = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize';$authorizationData->Authentication->TokenEndpoint = 'https://login.microsoftonline.com/common/oauth2/v2.0/token';// 设置报告请求$reportRequest = new ReportRequest();$reportRequest->Format = ReportFormat::Csv;$reportRequest->ReportName = 'Account Performance Report';$reportRequest->ReturnOnlyCompleteData = false;$reportRequest->Aggregation = ReportAggregation::Summary;$reportRequest->ReportTime = new ReportTime();$reportRequest->ReportTime->PredefinedTime = ReportTime::LastSevenDays;$reportRequest->ReportTime->CustomDateRangeStart = new DateRange();$reportRequest->ReportTime->CustomDateRangeStart->Day = 1;$reportRequest->ReportTime->CustomDateRangeStart->Month = 1;$reportRequest->ReportTime->CustomDateRangeStart->Year = 2022;$reportRequest->ReportTime->CustomDateRangeEnd = new DateRange();$reportRequest->ReportTime->CustomDateRangeEnd->Day = 31;$reportRequest->ReportTime->CustomDateRangeEnd->Month = 1;$reportRequest->ReportTime->CustomDateRangeEnd->Year = 2022;$reportRequest->Columns = [ AccountPerformanceReportColumn::TimePeriod, AccountPerformanceReportColumn::AccountId, AccountPerformanceReportColumn::AccountName, AccountPerformanceReportColumn::Impressions, AccountPerformanceReportColumn::Clicks, AccountPerformanceReportColumn::Ctr, AccountPerformanceReportColumn::AverageCpc, AccountPerformanceReportColumn::Spend, AccountPerformanceReportColumn::Conversions, AccountPerformanceReportColumn::ConversionRate,];$reportRequest->Sort = [ AccountPerformanceReportSort::TimePeriod,];$reportRequest->Filter = new AccountPerformanceReportFilter();$reportRequest->Filter->DeviceType = ['Computer'];// 发送报告请求$reportRequests = [$reportRequest];$reportingService = new ReportingService($authorizationData);$response = $reportingService->SubmitGenerateReport( $reportRequests, ServiceClientType::ReportingVersion13);// 获取报告下载链接$reportDownloadUrl = $response->ReportDownloadUrl;// 输出报告下载链接echo "报告下载链接: " . $reportDownloadUrl;使用Bing Ads API PHP报告请求获取广告报告数据如何使用Bing Ads API PHP报告请求来获取广告报告数据?这是一个常见的问题,尤其是对于那些需要快速分析和处理大量广告数据的广告主和营销人员。Bing Ads API提供了一种简便的方式来获取广告相关的数据,而无需手动下载报告。以下是一个案例代码,展示了如何使用Bing Ads API PHP报告请求来获取广告报告数据。案例代码解析首先,我们需要设置授权数据。这包括您的客户端ID、客户端密钥和重定向URI等信息。这些信息将用于进行OAuth身份验证。然后,我们设置报告请求。在这个案例中,我们创建了一个“Account Performance Report”的报告请求。我们指定了报告的格式为CSV,并设置了报告的时间范围为过去7天。您可以根据自己的需求来自定义报告的时间范围。接下来,我们指定了报告的列和排序方式。在这个案例中,我们选择了一些常用的列,如时间段、账户ID、展示次数、点击次数、点击率等。我们还指定了按时间段进行排序。最后,我们发送报告请求,并获取报告下载链接。使用Bing Ads API PHP报告请求,您可以轻松地获取广告相关的数据,而无需手动下载报告。这是一个非常方便的功能,特别适用于需要快速分析和处理大量数据的广告主和营销人员。如果您需要获取广告报告数据,不妨尝试使用Bing Ads API PHP报告请求,它将为您节省大量的时间和精力。以上是关于使用Bing Ads API PHP报告请求的文章,希望对您有所帮助!