1
$KEY_FILE_LOCATION = __DIR__ . '/service-account-credentials.json'; 

// Create and configure a new client object. 
$client = new \Google_Client(); 
$client->setApplicationName("Hello Analytics Reporting"); 
$client->setAuthConfig($KEY_FILE_LOCATION); 
$client->setScopes(['https://www.googleapis.com/auth/analytics']); 
$analytics = new \Google_Service_Analytics($client); 

// Construct the body of the request and set its properties. 
$profile = new \Google_Service_Analytics_Profile(); 
$profile->setName('View name'); 

$analytics->management_profiles->insert('123425914', 'UA-2344718-15', $profile); 

我尝试在GA应用上插入视图,但API返回insufficient permissions error插入新Google分析视图时权限不足错误

当我试图获取数据,如果我输入了错误$VIEW_ID然后打印相同的错误。

我在insert方法

  1. 现有VIEW_ID输入这些PARMS - 如果不输入任何存在VIEW_ID发生同样的错误。

  2. 第二参数已存在APP_ID。

你在这里看到一些错误吗?我仔细检查GA仪表板上的权限,一切似乎都没有问题。

回答

2
  1. 您正在进行身份验证的用户对Google Analytics帐户没有管理权限。
  2. 您尚未收到Management API上写入方法的测试版访问权限。

Views (Profiles): insert

写在管理API(例如创建,更新,删除,补丁)的网络媒体资源,视图(配置文件)和目标资源业务目前可在有限的开发者预览公测。如果您有兴趣使用这些功能,request access to the beta