谷歌分析API->;管理人员每天上传PHP
我只是尝试上载成本源数据,脚本为:谷歌分析API->;管理人员每天上传PHP,php,google-analytics,google-analytics-api,Php,Google Analytics,Google Analytics Api,我只是尝试上载成本源数据,脚本为: require_once('Google/Client.php'); require_once('Google/Service/Analytics.php'); const ANALYTICS_SCOPE = 'https://www.googleapis.com/auth/analytics'; const CLIENT_ID = 'xxxx.apps.googleusercontent.com'; const SERVICE_E
require_once('Google/Client.php');
require_once('Google/Service/Analytics.php');
const ANALYTICS_SCOPE = 'https://www.googleapis.com/auth/analytics';
const CLIENT_ID = 'xxxx.apps.googleusercontent.com';
const SERVICE_EMAIL = 'xxxx@developer.gserviceaccount.com';
const KEY_FILE_PATH = 'Google/keys/xxxx-privatekey.p12';
const VIEW_ID = 'xxxx';
const accountId = 'xxxx';
const webPropertyId = 'UA-xxxx-1';
const customDataSourceId = 'xxxx-wAyw';
$client = new Google_Client();
$client->setApplicationName( 'Analytics' );
$client->setScopes( ANALYTICS_SCOPE );
$client->setClientId( CLIENT_ID );
$client->setAssertionCredentials(
new Google_Auth_AssertionCredentials(
SERVICE_EMAIL,
array( ANALYTICS_SCOPE ),
file_get_contents( KEY_FILE_PATH )
)
);
$service = new Google_Service_Analytics( $client );
$results = $service->management_dailyUploads->upload(
accountId,
webPropertyId,
customDataSourceId,
date("Y-m-d"),
1,
'cost',
array(
"reset" => true,
"data" => file_get_contents("csv/1239709550_sample.csv"),
'mimeType' => 'application/octet-stream',
'uploadType' => 'media'
)
);
print_r($results);
我有一个错误:
"(403) User does not have permission to perform this operation."
,“用户管理”有,用户xxx@developer.gserviceaccount.com拥有“管理用户、编辑、协作、阅读和分析”权限
,“团队”用户xxx@developer.gserviceaccount.com,具有“可以编辑”权限。请确保您在Google Analytics admin的“帐户”级别添加了该用户,如果您仅在查看(配置文件)级别添加了该用户,则该功能将无法工作。您不需要将它们添加到code.google.com/console中。