承接 flyhjaelp/gmail2laravel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

flyhjaelp/gmail2laravel

Composer 安装命令:

composer require flyhjaelp/gmail2laravel

包简介

A Laravel package to help manage multiple Gmail Clients on the same platform.

README 文档

README

Latest Version on Packagist Software License Total Downloads Build Status

A Laravel package to help manage multiple Gmail Clients on the same platform.

This package is build on version 2.0 of the Official google/apiclient package.

Table of Contents

Installation

You can use Composer or simply Download the Release

$ composer require flyhjaelp/gmail2laravel

Usage

Requirements

Instantiating a Google Client Object with multiple Gmail clients

$credentialsPath = "path/to/credentials/file.json";

$googleClient    =  new gmail2laravel($credentials);

$gmailClient     =  $googleClient->getGmailClient('your.email@domain.com');

Calling a method

// get an email
$emails = $gmailClient->user_messages->get('your.email@domain.com',$messageId);

// fetching all labels
$labels =  $gmailClient->user_labels->listUsersLabels('me');

List of methods

$googleClient  =  new gmail2laravel($credentials);

$googleClient()->getGmailClient($email)

$googleClient()->deleteGmailClient($email)

$googleClient()->getEmailsFromAllClients($email)

$googleClient()->availableClients($email)

$googleClient()->enableBatch($email)

$googleClient()->disableBatch($email)

Additional list of methods

These methods are being imported from the main Google Gmail Api Package, and can be called as explained in the Gmail API documentation, where a broader description of the parameters required and the response is being provided. Link are provided bellow to each resource.

Setup

Google Developer project

The package makes usage of the Google API library. To gain access to the emails, a Google Cloud Project has to be created. A guide on how to do that can be found on the Google SDK platform Link

Note: the domain extension is important, as you will be able to access emails only from that domain. When creating a new Gmail Client instance, a check will be done automatically if the supplied user email address exists inside the g suite domain.

Service account client

After creating a new project, add Gmail API from the API Library and enable it on the project. After that, you need to assign it a Service account client, which you can create from the Google Console meu.

alt text

Note : the service is available only for G-Suite users.

alt text  After you generate a Service user, assign it to the project and provide it the wanted access rights. Its important to add it to the project and not to the Gmail Api, so you have access to other apis included in the project.

Its best practices to separate APIs into separate projects if they are not related in usage.

Keep in mind that you can have multiple services that are assigned to different tasks. You are limited to 100 services per project. The project limit is connected to the quota usage of each project. The quota usage is explained here: Quotas

Roles and Permissions

To access Gmail Resources through a Service account client, you need to assign roles and permission to it. Depending to what the purpose of the project is, you need to add the required permissions. An example

Quotas

For every Developer Project that usage the Gmail API, there is a quota usage measured by the Google servers. A list of the quota price can be found here.

Keep in mind , each type of request is calculated a different amount of quota. This quotas are being added to the quota units per day (1.000.000 default)

and the quota_units_per_user_per_second ( 250 default).

Exceptions and errors

Mention : keep in mind that these exceptions are being thrown by the Google API endpoints, and not by this package. The google project is a very strict environment and rules which may not be imediately obvious may take place. The official documentation provides answer to some of the best practices on how to manage and access the respu

Domain wide delegation (DWD)

Google_Service_Exception: {
  "error": "unauthorized_client",
  "error_description": "Client is unauthorized to retrieve access tokens using this method."
}

This is a common error when running an API call with a service account but not properly completing the domain-wide delegation (DWD) or because the authorization in the admin console has not propagated yet.

This article explains in details the process of DWD.

Domain wide delegation (DWD)

Google_Service_Exception: {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "forbidden",
    "message": "Delegation denied for your.email@domain.com"
   }
  ],
  "code": 403,
  "message": "Delegation denied for your.email@domain.com"
 }
}

This error happens when the Gmail Client is setup for a specific email address and then the method call is being provided in the arguments with a different user id/email. You need to manage in the call which GmailClient to use and provide as the user id the value of 'me', and the code will take the associated email in return. Example.

//direct call with direct return from the google client
$googleClient->$gmailClient('dave@gmail.com')->users_labels->listUsersLabels('me');

Message not found

Google_Service_Exception: {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}

The message you are trying to fetch is no longer available on the email address, due to maybe permanent deletion or wrong message id. Keep in mind that in some cases, the message id is the same as the thread id

Quota limit reached

Google_Service_Exception: {
 "error": "rate_limit_exceeded"
}

Exceeding a rate limit will cause an HTTP 403 or HTTP 429 Too Many Requests response and your app should respond by retrying with exponential backoff. Link to best practices guides to avoid exceeding the limits and how much quota each type of request uses link.

Changelog

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md for details and a todo list.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Note: Its your responsibility to ensure the storage of the service credentials key. Do not publish them on your repo, and the path to the key, should never be stored directly.

Credits

License

The MIT License (MIT). Please see License File for more information.

flyhjaelp/gmail2laravel 适用场景与选型建议

flyhjaelp/gmail2laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.17k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2019 年 01 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 flyhjaelp/gmail2laravel 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.17k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-03