php - 插入新的 Google 分析 View 时出现权限不足错误

标签 php google-analytics google-api google-analytics-api google-api-php-client

$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 App 上插入 View ,但 API 返回 insufficient permissions error .

当我输入错误 $VIEW_ID 尝试获取数据时然后打印相同的错误。

我已经在插入方法中输入了这些参数
  • 现有的 VIEW_ID - 如果输入不存在的 VIEW_ID,则会发生同样的错误。
  • 第二个参数存在 APP_ID。

  • 你看到这里有什么错误吗?我仔细检查了 GA 仪表板上的权限,一切似乎都很好。

    最佳答案

  • 您进行身份验证的用户没有 Google Analytics 帐户的管理员权限。
  • 您尚未获得对 Management API 上写入方法的测试访问权限。

  • Views (Profiles): insert

    Write operations in the Management API (e.g. create, update, delete, patch) for Web Property, View (Profile), and Goal resources are currently available as a developer preview in limited beta. If you're interested in using these features, request access to the beta.

    关于php - 插入新的 Google 分析 View 时出现权限不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44500224/

    相关文章:

    django - 属性错误: 'WSGIRequest' object has no attribute 'request' on OAuth2Decorator

    php - 左加入分页(LIMIT)

    php - 修订控制程序的制作方法

    javascript - 使用 JavaScript 访问 div 内的嵌套值

    ssl - 没有来自 Google Analytics 的 SSL 流量

    google-analytics - 特定onClick URL的GTM触发器

    google-analytics - Google Analytics - 无需登录即可访问 api

    .net - Google API 和 .NET Compact Framework

    php - 代码可以在 jsfiddle 中运行,但不能在 localserver 中运行

    php - 反馈系统只允许每个用户 1 个