revolution/laravel-google-searchconsole

Laravel的Google SearchConsole API

4.0.1 2024-08-25 02:24 UTC

This package is auto-updated.

Last update: 2024-09-25 02:36:41 UTC


README

Build Status Maintainability Test Coverage

https://developers.google.com/webmaster-tools

要求

  • PHP >= 8.2
  • Laravel >= 11.0

版本控制

  • 基本: semver
  • 删除旧PHP或Laravel版本: +0.1. composer应该可以很好地处理。
  • 仅支持最新主要版本(master分支),但您可以向旧分支提交PR。

安装

composer require revolution/laravel-google-searchconsole

获取API凭证

https://developers.google.com/console
启用Google Search Console API

config/google.php

    'client_id'        => env('GOOGLE_CLIENT_ID', ''),
    'client_secret'    => env('GOOGLE_CLIENT_SECRET', ''),
    'redirect_uri'     => env('GOOGLE_REDIRECT', ''),
    'scopes'           => [\Google\Service\Webmasters::WEBMASTERS],
    'access_type'      => 'offline',
    'approval_prompt'  => 'force',
    'prompt'           => 'consent', //"none", "consent", "select_account" default:none

config/service.php for Socialite

    'google' => [
        'client_id'     => env('GOOGLE_CLIENT_ID', ''),
        'client_secret' => env('GOOGLE_CLIENT_SECRET', ''),
        'redirect'      => env('GOOGLE_REDIRECT', ''),
    ],

根据需要配置.env

GOOGLE_APPLICATION_NAME=

GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT=

查询类

Google\Service\Webmasters\SearchAnalyticsQueryRequest的子类。

制作命令

app/Search下创建

php artisan make:search:query NewQuery 

查询类必须具有init()方法。

namespace App\Search;

use Revolution\Google\SearchConsole\Query\AbstractQuery;

class NewQuery extends AbstractQuery
{
    public function init(): void
    {
        $this->setStartDate(now()->subMonthWithoutOverflow()->toDateString());
        $this->setEndDate(now()->toDateString());
        $this->setDimensions(['query']);
        $this->setAggregationType(['auto']);
        $this->setRowLimit(100);
    }
}

许可证

MIT