Google Analytics API v3 > analytics.management.uploads.uploadData 权限不足问题
Google Analytics API v3 > analytics.management.uploads.uploadData Insufficient Permission Problem
我开发了一个 PHP 应用程序,可以将退款数据发送给分析。我想通过数据上传发送退款。我使用 Google APIs PHP client library so the following code uses the method you can find here: https://github.com/google/google-api-php-client-services/blob/a016ea7b6d47e1fd1f43d89ebd80059d4bfadb32/src/Google/Service/Analytics/Resource/ManagementUploads.php
$dataTxt = "ga:transactionId;ga:quantityRefunded;ga:productSku;ga:productPrice
dcn15355709483497;1;2811841;38.47
dcn15360003605123;1;3568636;89.35
dcn15359475814131;1;4238610;28.98";
$accountId = "xxxx"; # admin -> choose account -> view properties
$webPropertyId = "xxxx"; # admin -> choose property -> view properties
$customDataSourceId = "xxxx";
$data = array(
'data' => $dataTxt,
'mimeType' => 'application/octet-stream',
'uploadType' => 'media');
try {
$this->service->management_uploads->uploadData(
$accountId,
$webPropertyId,
$customDataSourceId,
$data
);
} catch (apiServiceException $e) {
print 'There was an Analytics API service error '
. $e->getCode() . ':' . $e->getMessage();
} catch (apiException $e) {
print 'There was a general API error '
. $e->getCode() . ':' . $e->getMessage();
}
我授予 API 用户完全访问权限并授予他任何权限。我仍然收到错误消息:
Error calling POST https://www.googleapis.com/upload/analytics/v3/management/accounts/2465955/webproperties/UA-2465955-20/customDataSources/gx3hqqEjR7qBrcgrIDkToQ/uploads?uploadType=media: (403) Insufficient Permission
我希望有人能帮助我,因为我 运行 没有答案和问题。
(403) Insufficient Permission
表示与您进行身份验证的用户未授予您足够的权限来执行您正在尝试执行的操作。不幸的是,您没有包含您的身份验证代码。但我可以告诉你 upload data
要求用户使用以下范围之一进行身份验证
您应该遵循此示例进行身份验证PHP quick start确保您使用的是正确的范围。
那么下面的请求就会运行.
/**
* Note: This code assumes you have an authorized Analytics service object.
* See the Data Import Developer Guide for details.
*/
/**
* This request uploads a file to a custom data source.
*/
try {
$analytics->management_uploads->uploadData(
'123456',
'UA-123456-1',
'122333444455555',
array('data' => file_get_contents('example.csv'),
'mimeType' => 'application/octet-stream',
'uploadType' => 'media'));
} catch (apiServiceException $e) {
print 'There was an Analytics API service error '
. $e->getCode() . ':' . $e->getMessage();
} catch (apiException $e) {
print 'There was a general API error '
. $e->getCode() . ':' . $e->getMessage();
}
我开发了一个 PHP 应用程序,可以将退款数据发送给分析。我想通过数据上传发送退款。我使用 Google APIs PHP client library so the following code uses the method you can find here: https://github.com/google/google-api-php-client-services/blob/a016ea7b6d47e1fd1f43d89ebd80059d4bfadb32/src/Google/Service/Analytics/Resource/ManagementUploads.php
$dataTxt = "ga:transactionId;ga:quantityRefunded;ga:productSku;ga:productPrice
dcn15355709483497;1;2811841;38.47
dcn15360003605123;1;3568636;89.35
dcn15359475814131;1;4238610;28.98";
$accountId = "xxxx"; # admin -> choose account -> view properties
$webPropertyId = "xxxx"; # admin -> choose property -> view properties
$customDataSourceId = "xxxx";
$data = array(
'data' => $dataTxt,
'mimeType' => 'application/octet-stream',
'uploadType' => 'media');
try {
$this->service->management_uploads->uploadData(
$accountId,
$webPropertyId,
$customDataSourceId,
$data
);
} catch (apiServiceException $e) {
print 'There was an Analytics API service error '
. $e->getCode() . ':' . $e->getMessage();
} catch (apiException $e) {
print 'There was a general API error '
. $e->getCode() . ':' . $e->getMessage();
}
我授予 API 用户完全访问权限并授予他任何权限。我仍然收到错误消息:
Error calling POST https://www.googleapis.com/upload/analytics/v3/management/accounts/2465955/webproperties/UA-2465955-20/customDataSources/gx3hqqEjR7qBrcgrIDkToQ/uploads?uploadType=media: (403) Insufficient Permission
我希望有人能帮助我,因为我 运行 没有答案和问题。
(403) Insufficient Permission
表示与您进行身份验证的用户未授予您足够的权限来执行您正在尝试执行的操作。不幸的是,您没有包含您的身份验证代码。但我可以告诉你 upload data
要求用户使用以下范围之一进行身份验证
您应该遵循此示例进行身份验证PHP quick start确保您使用的是正确的范围。
那么下面的请求就会运行.
/**
* Note: This code assumes you have an authorized Analytics service object.
* See the Data Import Developer Guide for details.
*/
/**
* This request uploads a file to a custom data source.
*/
try {
$analytics->management_uploads->uploadData(
'123456',
'UA-123456-1',
'122333444455555',
array('data' => file_get_contents('example.csv'),
'mimeType' => 'application/octet-stream',
'uploadType' => 'media'));
} catch (apiServiceException $e) {
print 'There was an Analytics API service error '
. $e->getCode() . ':' . $e->getMessage();
} catch (apiException $e) {
print 'There was a general API error '
. $e->getCode() . ':' . $e->getMessage();
}