我一直在为adsense(admob)报告下载自动化开发自动化脚本,我完成了一个完整的脚本,该脚本使用了对api的自定义直接http调用,但是在分析错误代码时我才知道该服务api工作人员帐户无法访问显然是报告的“个人”数据。在没有(或几乎从没有)人为干预的情况下,自动化下载或报告的最佳方法是什么?我已经查看了Google所提供的php api库的文档,但是api已经过时了-最新更新是5年前。
https://developers.google.com/adsense/management/ 如果您转到客户端库->了解更多-> PHP->浏览示例。
在这里可以用来完成任务的任何新和仍然相关信息吗?
更新。 使用此代码生成报告:
<?php
require_once 'vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig('oauth_client.json');
$client->setAccessType("offline"); // offline access
$client->setIncludeGrantedScopes(true); // incremental auth
$client->addScope("https://www.googleapis.com/auth/adsense");
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/go');
$auth_url = $client->createAuthUrl();
if( isset($_GET['code']) ){
$code=$_GET['code'];
}else{
$code=null;
}
if(!$code){
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
}else{
$client->authenticate($code);
$access_token = $client->getAccessToken();
$client->setAccessToken($access_token);
$adsense = new Google_Service_Adsense($client);
$reports = $adsense->reports;
$csv = $reports->generate('2018-08-01','2018-08-05',array("metric" => ["VIEWED_IMPRESSIONS","CLICKS","EARNINGS"],"dimension"=>["DATE", "COUNTRY_CODE","APP_NAME"],"currency"=>"EUR"));
}
代码按原样工作,但是,如果我添加“ alt” =>“ csv”参数:
$csv = $reports->generate('2018-08-01','2018-08-05',array("metric" => ["VIEWED_IMPRESSIONS","CLICKS","EARNINGS"],"dimension"=>["DATE", "COUNTRY_CODE","APP_NAME"],"currency"=>"EUR",'alt' =>'csv'));
结果为“空白”:
Google_Service_AdSense_AdsenseReportsGenerateResponse Object
(
[collection_key:protected] => warnings
[averages] =>
[endDate] =>
[headersType:protected] => Google_Service_AdSense_AdsenseReportsGenerateResponseHeaders
[headersDataType:protected] => array
[kind] =>
[rows] =>
[startDate] =>
[totalMatchedRows] =>
[totals] =>
[warnings] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
我知道如何清洁卫生,不要为此而责骂我,我想让它首先工作。如何添加alt = media和alt = csv参数?