hkirsman / google-search-console
此包最新版本(dev-master)没有提供许可证信息。
google/apiclient 的包装器,用于访问和检索 Google Search Console 的数据。
dev-master
2016-09-06 18:22 UTC
Requires
- google/apiclient: ^2.0.0@RC
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-09-11 19:46:59 UTC
README
使用 PHP 访问和检索 Google Search Console 数据的 google/apiclient 包装器。您可以在 https://packagist.org.cn/packages/hkirsman/google-search-console 和 https://github.com/hkirsman/hkirsman-google-search-console 找到此项目。
安装(使用 Composer)
将 hkirsman/google-search-console 添加到您的项目中
composer require hkirsman/google-search-console:dev-master
从 https://console.developers.google.com 获取密钥。如果您还没有项目,您需要创建一个项目,启用“Google Search Console API”并创建“服务账户密钥”(json 格式)。将此密钥文件添加到项目根目录或定义自定义路径,如下所示
$searchConsole = new SearchConsoleApi('/foo/bar/service-account.json');
而不是仅仅
$searchConsole = new SearchConsoleApi();
您还需要获取服务账户 ID (XXXX@developer.gserviceaccount.com) 并将其添加为用户在 https://www.google.com/webmasters/tools/。
示例
尝试这个示例文件。将 http://www.example.com/ 替换为您的 URL,同时也要将 'expression' => '/SUBPATH/', 替换。
<?php require_once 'vendor/autoload.php'; use HannesKirsman\GoogleSearchConsole\SearchConsoleApi; $searchConsole = new SearchConsoleApi(); $options = SearchConsoleApi::getDefaultOptions(); $options['site_url'] = 'http://www.example.com/'; $options['start_date'] = date('Y-m-d', strtotime("-3 days"));; $options['end_date'] = date('Y-m-d', strtotime("-3 days"));; $options['setDimensionFilterGroups'] = array( 'filters' => array ( 'dimension' => 'page', 'operator' => 'contains', 'expression' => '/SUBPATH/', ), ); $rows = $searchConsole->getRows($options); print_r($rows);