Php 谷歌分析API包括路径
我正在尝试使用Google提供的内容在代码中动态设置包含路径: 设置包含路径获取包含路径。路径分隔符。”/path/to/google-api-php-client/src' 我对PHP还比较陌生,我将假设/path/to/需要更改为其他内容。我曾尝试将其设置为/home/expiredf/public_html/google-api-php-client/src,但不起作用 有人能帮我完成这个教程吗Php 谷歌分析API包括路径,php,google-analytics,google-analytics-api,google-api-php-client,Php,Google Analytics,Google Analytics Api,Google Api Php Client,我正在尝试使用Google提供的内容在代码中动态设置包含路径: 设置包含路径获取包含路径。路径分隔符。”/path/to/google-api-php-client/src' 我对PHP还比较陌生,我将假设/path/to/需要更改为其他内容。我曾尝试将其设置为/home/expiredf/public_html/google-api-php-client/src,但不起作用 有人能帮我完成这个教程吗 在任何人将其他问题与答案联系起来之前,我已经浏览了其中的大多数问题,并试图实现它们的解决方案,
在任何人将其他问题与答案联系起来之前,我已经浏览了其中的大多数问题,并试图实现它们的解决方案,但它们并不适合我,因为它们似乎是以更高的PHP知识来解释的。感谢您提供简单的基本答案。对于您的问题,最好的答案是不要使用该教程。该教程已经非常过时,并且使用了旧的PHP客户机库,这已经被报告给了 PHP客户端库 最新版本的Google PHP客户端库可以在Github上找到。每当发生任何变化时,都会定期更新此客户端库。您需要将整个目录复制到应用程序的目录中。我不建议只带你需要的文件,除非你真的知道你在做什么 Oauth2 Oauth2有三个步骤,这就是为什么它被称为三条腿身份验证。在第一步中,您要求用户授予您访问权限,第二步用户授予您访问权限,第三步也是最后一步,您将用户授予您的访问权限交换为对数据的访问权限
<?php
require_once 'Google/Client.php';
require_once 'Google/Service/Analytics.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$client->setDeveloperKey("{devkey}");
$client->setClientId('{clientid}.apps.googleusercontent.com');
$client->setClientSecret('{clientsecret}');
$client->setRedirectUri('http://www.daimto.com/Tutorials/PHP/Oauth2.php');
$client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
//For loging out.
if ($_GET['logout'] == "1") {
unset($_SESSION['token']);
}
// Step 2: The user accepted your access now you need to exchange it.
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
// Step 1: The user has not authenticated we give them a link to login
if (!$client->getAccessToken() && !isset($_SESSION['token'])) {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
// Step 3: We have access we can now create our service
if (isset($_SESSION['token'])) {
print "<a class='logout' href='".$_SERVER['PHP_SELF']."?logout=1'>LogOut</a><br>";
$client->setAccessToken($_SESSION['token']);
$service = new Google_Service_Analytics($client);
// request user accounts
$accounts = $service->management_accountSummaries->listManagementAccountSummaries();
foreach ($accounts->getItems() as $item) {
echo "Account: ",$item['name'], " " , $item['id'], "<br /> \n";
foreach($item->getWebProperties() as $wp) {
echo ' WebProperty: ' ,$wp['name'], " " , $wp['id'], "<br /> \n";
$views = $wp->getProfiles();
if (!is_null($views)) {
foreach($wp->getProfiles() as $view) {
// echo ' View: ' ,$view['name'], " " , $view['id'], "<br /> \n";
}
}
}
} // closes account summaries
}
print "<br><br><br>";
print "Access from google: " . $_SESSION['token'];
?>
这段代码直接取自我的教程:教程是最新的。如果这篇文章是旧的,你可能想看看代码中是否有任何更改。那篇教程已经过时了,试试这个:还没有实现任何代码,但事实上你为我指出了关于教程的正确方向,我已经标记为正确:现在实现了,效果很好,完全达到了我想要的效果,现在开始阅读更多的数据。谢谢您: