PHPackages                             hoanghiep/google - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. hoanghiep/google

ActiveLibrary[API Development](/categories/api)

hoanghiep/google
================

google in laravel

011PHP

Since Jul 7Pushed 9y ago1 watchersCompare

[ Source](https://github.com/thandonguocmo2020/laravel-google)[ Packagist](https://packagist.org/packages/hoanghiep/google)[ RSS](/packages/hoanghiep-google/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Hoàng Hiệp API Google Client in Laravel Master
==============================================

[](#hoàng-hiệp-api-google-client-in-laravel-master)

Chuẩn Bị
========

[](#chuẩn-bị)

Vào ứng dụng laravel vào file composer.json thêm dòng :

"minimum-stability": "dev",

Để sửa lỗi

at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability

sau đó mở composer chạy lệnh tải gói

composer require hoanghiep/laravel-google-api

Sau khi tải gói lưu ý chuẩn bị :

- bật apache rewrite\_module

Sửa lỗi cURL error 60: SSL :

tải file

để vào thư mục php của bạn

sau đó sửa file php.ini

tìm dòng ;curl.cainfo sửa thành

curl.cainfo= "path/cacert.pem"

Lưu ý các phiên bản sử dụng có thể ko sửa được do phiên bản apache ví dụ dùng wampp 5.5.12 ko được nhưng bản 5.6.12 lại được.

1. cấu hình database.
=====================

[](#1-cấu-hình-database)

cấu hình cơ sở dữ liệu trong tập tin .env

2. thêm provider vào config/app.php
===================================

[](#2-thêm-provider-vào-configappphp)

Hoanghiep\\Googleapi\\GoogleClientProvider::class

3. Chạy lệnh xuất những file cần thiết
======================================

[](#3-chạy-lệnh-xuất-những-file-cần-thiết)

php artisan vendor:publish

Các file được tạo ra gồm

- file tạo database lưu trữ trong database\\migrations\\2016\_07\_03\_010808\_create\_googles\_table.php
- file config dòng chảy xác thực trong config/google.php
- file làm việc với model trong app\\Google.php
- file mẫu các dịch vụ google sẽ sử dụng trong app\\Providers\\GoogleServiceProvider.php
- file mẫu controller sử dụng gọi server và lấy mã ủy quyền và sử dụng thư viện trong app\\Http\\Controllers\\Hoanghiep\\UserinfoController.php

4. Cấu hình dòng chảy tới máy chủ google trong config/google.php
================================================================

[](#4-cấu-hình-dòng-chảy-tới-máy-chủ-google-trong-configgooglephp)

- AppName =&gt; tên ứng dụng
- AppKey =&gt; khóa API truy cập dữ liệu công cộng
- client\_id =&gt; khóa client id máy chủ ủy quyền
- client\_secret =&gt; khóa lựa chọn máy chủ ủy quyền
- redirect =&gt; thay thế bằng url dụng [http://localhost/{projiect-name}/social/google/handle/token](http://localhost/%7Bprojiect-name%7D/social/google/handle/token) =&gt; yêu cầu trong máy chủ bắt buộc có url này để gói xử lý.
- scopes=&gt; phạm vi cần yêu cầu người dùng đồng ý để có thể truy cập dữ liệu
- redirectToPath =&gt; sau khi sử lý thành công url sẽ được chuyển hướng tới trang bạn cần chuyển demo là trang /test và controller xử lý là UserinfoController@index

5. Chạy lệnh tạo bảng dữ liệu
=============================

[](#5-chạy-lệnh-tạo-bảng-dữ-liệu)

php artisan migrate

6. Chạy thử dòng chảy
=====================

[](#6-chạy-thử-dòng-chảy)

localhost/project-name/social/google/redirect

7. Thấy báo lỗi không tìm thấy route url /test
==============================================

[](#7-thấy-báo-lỗi-không-tìm-thấy-route-url-test)

NotFoundHttpException in RouteCollection.php line 161:

sửa khai báo url như sau :

vào app/Http/routes.php

thêm định nghĩa url /test gọi đến UserinfoController@index

Route::get('/test',\["middleware"=&gt;"web","uses"=&gt;"Hoanghiep\\UserinfoController@index"\]);

nếu ko dùng user /test định nghĩa trong file config/google redirectPath bạn dùng home chẳng hạn thì nó sẽ như này

Route::get('/home',\["middleware"=&gt;"web","uses"=&gt;"Hoanghiep\\UserinfoController@index"\]);

8. Xem kết quả và dựa vào controller làm mẫu để khởi tạo controller khác muốn sử dụng thẻ ủy quyền và truy cập dữ liệu của google api.
======================================================================================================================================

[](#8-xem-kết-quả-và-dựa-vào-controller-làm-mẫu-để-khởi-tạo-controller-khác-muốn-sử-dụng-thẻ-ủy-quyền-và-truy-cập-dữ-liệu-của-google-api)

9 Extension kế thừa class GoogleController
==========================================

[](#9--extension-kế-thừa-class-googlecontroller)

use \\Hoanghiep\\Googleapi\\hoanghiep\\GoogleController;

// ke thua lop xu ly class UserinfoController extends GoogleController {

}

- config google client

$client = App::make("Google\_Client");

- handle Token "xử lý token"

$this-&gt;handleProvider($request);

- getToken "lấy token và số lần làm mới thẻ"

$token = $this-&gt;client\_array;

- Check Token

if (!isset($token\[0\])): return redirect()-&gt;route("google.redirect"); endif;

- get refresh\_Token "lấy số lần làm mới" $number\_refresh = $token\[0\];
- Check Token "kiểm tra nếu còn 1 thì làm yêu cầu truy cập lại " if ($number\_refresh == 1): return redirect()-&gt;route("google.redirect");
- getAccessToken "lấy thẻ truy cập" $accessToken = $token\[1\];
- setAccessToken "Sử dụng thẻ truy cập" $client-&gt;setAccessToken($accessToken);
- gọi api đã khai báo trong và truyền vào $client hiện tại $google\_oauth = App::make("Google\_Service\_Oauth2", \[$client\]); $user = $google\_oauth-&gt;userinfo-&gt;get();
- hiển thị kết quả

    ```
     dd($user);

    ```

Sử dụng Class Controller Khác Và Provider Service Khác ví dụ Youtube
====================================================================

[](#sử-dụng-class-controller-khác-và-provider-service--khác-ví-dụ-youtube)

1. Bật các API youtube service
2. Vào config/app.php thêm provider

    App\\Providers\\GoogleServiceProvider::class,
3. Thêm các class dịch vụ cần sử dụng ví dụ // ở trên class use Google\_Service\_Youtube; // thêm một class mới vào container service laravel trong method register(){

    $this-&gt;app-&gt;bind("Google\_Service\_Youtube", function ($app, array $client) { return new Google\_Service\_Youtube($client\[0\]); });

}

4. Cấu hình thêm ủy quyền mới phạm vi truy cập dữ liệu trong config/google.php chú ý bật các Api cần sử dụng
5. Khởi tạo route

Route::get('social/google/youtube',\["middleware"=&gt;"web","uses"=&gt;"Hoanghiep\\YoutubeController@index"\]);

4. Chạy lệnh tạo controller :

php artisan make:controller Hoanghiep\\YoutubeController

5. Vào file controller YoutubeController sử dụng lớp kế thừa GoogleClientController tương tự UserinfoController.php

trông như thế này :

handleProvider($request); $token = $this-&gt;client\_array; if (!isset($token\[0\])): return redirect()-&gt;route("google.redirect"); endif; $number\_refresh = $token\[0\]; if ($number\_refresh == 1): return redirect()-&gt;route("google.redirect"); endif; $accessToken = $token\[1\]; $client-&gt;setAccessToken($accessToken); $youtube = App::make("Google\_Service\_Youtube",\[$client\]); dd($youtube); } 7. khi chạy url : http://localhost/{project-name}/social/google/youtube Kết quả : Google\_Service\_YouTube {#193 ▼ +activities: Google\_Service\_YouTube\_Resource\_Activities {#187 ▶} +captions: Google\_Service\_YouTube\_Resource\_Captions {#192 ▶} +channelBanners: Google\_Service\_YouTube\_Resource\_ChannelBanners {#182 ▶} +channelSections: Google\_Service\_YouTube\_Resource\_ChannelSections {#190 ▶} +channels: Google\_Service\_YouTube\_Resource\_Channels {#213 ▶} +commentThreads: Google\_Service\_YouTube\_Resource\_CommentThreads {#212 ▶} +comments: Google\_Service\_YouTube\_Resource\_Comments {#211 ▶} +fanFundingEvents: Google\_Service\_YouTube\_Resource\_FanFundingEvents {#210 ▶} +guideCategories: Google\_Service\_YouTube\_Resource\_GuideCategories {#200 ▶} +i18nLanguages: Google\_Service\_YouTube\_Resource\_I18nLanguages {#199 ▶} +i18nRegions: Google\_Service\_YouTube\_Resource\_I18nRegions {#198 ▶} +liveBroadcasts: Google\_Service\_YouTube\_Resource\_LiveBroadcasts {#196 ▶} +liveChatBans: Google\_Service\_YouTube\_Resource\_LiveChatBans {#197 ▶} +liveChatMessages: Google\_Service\_YouTube\_Resource\_LiveChatMessages {#194 ▶} +liveChatModerators: Google\_Service\_YouTube\_Resource\_LiveChatModerators {#195 ▶} +liveStreams: Google\_Service\_YouTube\_Resource\_LiveStreams {#204 ▶} +playlistItems: Google\_Service\_YouTube\_Resource\_PlaylistItems {#203 ▶} +playlists: Google\_Service\_YouTube\_Resource\_Playlists {#202 ▶} +search: Google\_Service\_YouTube\_Resource\_Search {#201 ▶} +sponsors: Google\_Service\_YouTube\_Resource\_Sponsors {#205 ▶} +subscriptions: Google\_Service\_YouTube\_Resource\_Subscriptions {#188 ▶} +thumbnails: Google\_Service\_YouTube\_Resource\_Thumbnails {#189 ▶} +videoAbuseReportReasons: Google\_Service\_YouTube\_Resource\_VideoAbuseReportReasons {#181 ▶} +videoCategories: Google\_Service\_YouTube\_Resource\_VideoCategories {#216 ▶} +videos: Google\_Service\_YouTube\_Resource\_Videos {#206 ▶} +watermarks: Google\_Service\_YouTube\_Resource\_Watermarks {#218 ▶} +batchPath: null +rootUrl: "" +version: "v3" +servicePath: "youtube/v3/" +availableScopes: null +resource: null -client: Google\_Client {#179 ▶} +"serviceName": "youtube" }

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8016818?v=4)[thandonguocmo2020](/maintainers/thandonguocmo2020)[@thandonguocmo2020](https://github.com/thandonguocmo2020)

---

Top Contributors

[![thandonguocmo2020](https://avatars.githubusercontent.com/u/8016818?v=4)](https://github.com/thandonguocmo2020 "thandonguocmo2020 (3 commits)")

### Embed Badge

![Health badge](/badges/hoanghiep-google/health.svg)

```
[![Health](https://phpackages.com/badges/hoanghiep-google/health.svg)](https://phpackages.com/packages/hoanghiep-google)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35816.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

94452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
