gpt4 book ai didi

php - (403) 您的项目无权访问此功能

转载 作者:可可西里 更新时间:2023-11-01 00:09:09 25 4
gpt4 key购买 nike

一直关注有关如何插入网络属性的文档,以便我可以动态创建跟踪代码。目标是将我们的分析转移到 Google Analytics 中,并在分析下自动在他们自己的 Google 帐户上创建客户网站。在我在网上找不到什么之后,似乎这个功能可能被列入了白名单。所以我提出这个问题是为了弄清楚天气是否如此。文档很难弄清楚,因为它没有告诉您需要哪些字段、这些字段的含义等。而且 PHP 库的文档似乎已经过时了。必须更改大量示例代码的类名和方法名才能使其“正常工作”。

这是我用来测试此功能的代码片段。

<?php
require_once 'Google/Client.php';
require_once 'Google/Service/Analytics.php';
require_once 'Google/Service/Oauth2.php';

session_start();

$client = new Google_Client();

$client->setClientId('xxxxx');
$client->setClientSecret('xxxxxx');
$client->setRedirectUri('xxxxxxxx');
$client->setDeveloperKey('xxxxxxx');
$client->setScopes(
array(
'https://www.googleapis.com/auth/analytics.readonly',
'https://www.googleapis.com/auth/analytics',
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/analytics.edit',
'https://www.googleapis.com/auth/analytics.manage.users'
)
);

$oauth2 = new Google_Service_Oauth2($client);

if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}

if (isset($_REQUEST['logout'])) {
unset($_SESSION['access_token']);
}

if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
}

if (!$client->getAccessToken()) {
$authUrl = $client->createAuthUrl();

print "<a class='login' href='$authUrl'>Connect Me!</a>";

} else {
$analytics = new Google_Service_Analytics($client);

try {
$user = $oauth2->userinfo->get();

$permission = new Google_Service_Analytics_WebpropertyPermissions();
$permission->setEffective(array('EDIT', 'VIEW'));

$trackingObject = new Google_Service_Analytics_Webproperty();
$trackingObject->setAccountId($user['id']);
//$trackingObject->setDefaultProfileId($user['id']);
$trackingObject->setId('UA-xxxxx-1');
$trackingObject->setPermissions($permission);
$trackingObject->setIndustryVertical('INTERNET_AND_TELECOM');
$trackingObject->setLevel('STANDARD');
$trackingObject->setName('xxxxxx');
$trackingObject->setWebsiteUrl('xxxxxx');

$analytics->management_webproperties->insert($user['id'], $trackingObject);
$accounts = $analytics->management_accounts->listManagementAccounts();
echo '<pre>'; print_r($user); echo '</pre>';
echo '<pre>'; print_r($accounts); echo '</pre>';
die();

} catch (apiServiceException $e) {
// Error from the API.
print 'There was an API error : ' . $e->getCode() . ' : ' . $e->getMessage();

} catch (Exception $e) {
print 'There was a general error : ' . $e->getMessage();
}
}

我得到的异常(exception)是标题包含的内容。

最佳答案

写操作仍处于测试阶段。在使用此功能之前,您需要请求访问测试版。

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

更新:获得批准大约需要 3 周时间。当您获得批准后,您将收到一封来自 Google 的电子邮件,邀请您加入 Beta 测试组。

关于php - (403) 您的项目无权访问此功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22682554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com