定制 bronhy/google-my-business-php-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bronhy/google-my-business-php-client

Composer 安装命令:

composer require bronhy/google-my-business-php-client

包简介

Google My Business

README 文档

README

The Google My Business API client libraries wraps the functionality of the Google My Business API, and provide functionality common to all Google APIs, for example HTTP transport, error handling, authentication, JSON parsing, and support for protocol buffers.

This package contains the Service definition for MyBusiness and it depends on Google API PHP Client

You are welcome to contribute and ask for maintenance rights.

BIG NOTICE

Google is updating My Business API and exposing the new Service definitions in this library. https://github.com/googleapis/google-api-php-client-services. After the udpate is compleate this repository will be marked as DEPRECATED.

Requirements:

Google API PHP Client URL: https://github.com/google/google-api-php-client/releases

How to install

The easiest way to install is with composer.

composer require bronhy/google-my-business-php-client

Semantic Versioning

Do notice that google is not following semantic versioning RFC https://semver.org/ with this library. Since this package reflects the google versioning make sure that you lock to your version.

ie. composer require bronhy/google-my-business-php-client:4.8

Configure with Symfony framework

# config/services.yaml

parameters:
    app.google_credentials: '%env(json:base64:GOOGLE_CREDENTIALS)%' # exported json base64 encoded
    app.client_scope: 'https://www.googleapis.com/auth/plus.business.manage'
    app.redirect_url: '%env(GMB_REDIRECT_URI)%'

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
    
    Google_Client:
        class: Google_Client
        calls:
            - method: setAuthConfig
              arguments:
                  - '%app.google_credentials%'
            - method: addScope
              arguments:
                  - '%app.client_scope%'
            - method: setAccessType
              arguments:
                  - 'offline'
            - method: setRedirectUri # handy for local dev ie. https://localhost:8443/index.php 
              arguments:
                  - '%app.redirect_url%'
            - method: setLogger
              arguments:
                      - '@monolog.logger'
        tags:
            - { name: monolog.logger, channel: google-api-php-client }

    Google_Service_MyBusiness:
        class: Google_Service_MyBusiness
        arguments: ['@Google_Client']
# HelloController.php
<?php

/**
 * @Route("/hello/world") name="hello_world" methods=("GET")
 *
 * @param Google_Service_MyBusiness $myBusiness

 *
 * @return JsonResponse
 */
public function helloWorld(Google_Service_MyBusiness $myBusiness)
{
    // some logic
    return JsonResponse(['HelloWorld']);
}

Detailed error responses

To enable more detailed error messages in responses, such as absent required fields, add the following additional header to your requests:

X-GOOG-API-FORMAT-VERSION: 2

For additional information on error message responses, see the ErrorCode, ErrorDetail, InternalError, and ValidationError pages in the Shared.Types section.

$client = new \Google_Client(['api_format_v2' => true]);

Or with symfony in service_dev.yaml

# config/services_dev.yaml
parameters:
    ...
    app.client_debug:
        api_format_v2: true
    ...
    Google_Client:
        class: Google_Client
        arguments: ['%app.client_debug%'] 
        calls:
    ...

Authentication script examples

Service Account

Get and include the Google_Client as described above.

# src/index.php
require dirname(__DIR__) . '/vendor/autoload.php';

$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
// set the service account json file location manually
$client->setAuthConfig(__DIR__ . '/Data/service_account.json');
$client->setApplicationName("_Your_app_name_here_");
// set the scope to access GMBs
$client->setScopes([
    "https://www.googleapis.com/auth/business.manage"
]);
// if you have not enabled/ have access to GMB API you need to request it directly with Google and enable it through the project's API explorer; search for "Google My Business API" 

bronhy/google-my-business-php-client 适用场景与选型建议

bronhy/google-my-business-php-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 128.9k 次下载、GitHub Stars 达 23, 最近一次更新时间为 2020 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「google my business」 「mybusiness」 「gmb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bronhy/google-my-business-php-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bronhy/google-my-business-php-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 bronhy/google-my-business-php-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 128.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 23
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 23
  • Watchers: 4
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2020-01-20