happyr/google-api-bundle
Composer 安装命令:
composer require happyr/google-api-bundle
包简介
A Symfony2 Wrapper for the Google APIs Client Library for PHP
关键字:
README 文档
README
A symfony2 bundle to communicate to Google API. This bundle is a Symfony2 wrapper for the google apiclient. There are some services not yet implemented. Please submit a PR and I'm happy to merge.
Installation
Step 1: Using Composer
Install it with Composer!
// composer.json { // ... require: { // ... "happyr/google-api-bundle": "~2.1", } }
Then, you can install the new dependencies by running Composer's update
command from the directory where your composer.json file is located:
$ php composer.phar update
Step 2: Register the bundle
To register the bundles with your kernel:
<?php // in AppKernel::registerBundles() $bundles = array( // ... new HappyR\Google\ApiBundle\HappyRGoogleApiBundle(), // ... );
Step 3: Configure the bundle
# app/config/config.yml # you will get these parameters form https://code.google.com/apis/console/" happy_r_google_api: application_name: MySite oauth2_client_id: oauth2_client_secret: oauth2_redirect_uri: developer_key: site_name: mysite.com
Basic Usage
Step 1: Create a controller
Create a controller with authenticate and redirect methods.
<?php namespace AppBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\Request; class GoogleOAuthController extends Controller { /** * @Route("/oauth/google/auth") */ public function getAuthenticationCodeAction() { } /** * @Route("/oauth/google/redirect") */ public function getAccessCodeRedirectAction(Request $request) { } }
Step 2: Get the access code
Setup the required scope of your app and redirect the user to complete their part of the OAuth request.
// ... private $accessScope = [ \Google_Service_Calendar::CALENDAR ]; /** * @Route("/oauth/google/auth") */ public function getAuthenticationCodeAction() { $client = $this->container->get('happyr.google.api.client'); // Determine the level of access your application needs $client->getGoogleClient()->setScopes($this->accessScope); // Send the user to complete their part of the OAuth return $this->redirect($client->createAuthUrl()); } // ...
Step 3: Handle the redirect
Determine if an access code has been returned. If there is an access code then exchange this for an access token by using the client authenticate method.
// ... private $accessScope = [ \Google_Service_Calendar::CALENDAR ]; // ... /** * @Route("/oauth/google/redirect") */ public function getAccessCodeRedirectAction(Request $request) { if($request->query->get('code')) { $code = $request->query->get('code'); $client = $this->container->get('happyr.google.api.client'); $client->getGoogleClient()->setScopes($this->accessScope); $client->authenticate($code); $accessToken = $client->getGoogleClient()->getAccessToken(); // TODO - Store the token, etc... } else { $error = $request->query->get('error'); // TODO - Handle the error } } // ...
If successful the response should include access_token, expires_in, token_type, and created.
happyr/google-api-bundle 适用场景与选型建议
happyr/google-api-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 199.04k 次下载、GitHub Stars 达 48, 最近一次更新时间为 2013 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「google api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 happyr/google-api-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 happyr/google-api-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 happyr/google-api-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
Google Recaptcha Package For PHP front and backend.
A lightweight plain-PHP framework for database-backed CRUD APIs.
Modern, strongly-typed, PSR-compliant PHP client for the WeFact v2 API.
统计信息
- 总下载量: 199.04k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 48
- 点击次数: 13
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-07-04