Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Phillip Shipley:
Read and write Google Sheets from PHP
Jun 01, 2017 @ 10:57:44

Phillip Shipley has written up a post for his site walking you through the process of using PHP to read from and write to Google Sheets via the Google Sheets API.

This past week I needed to be able to read some data from a Google Sheet and then update a column for each row after processing it. This sort of thing should be simple, Google is built on APIs and has client SDKs for just about every language. I’ve also integrated with several Google Admin APIs previously so I expected this to be a breeze. I was wrong.

I started out by reading the Quickstart for Sheets API with the PHP Client, but almost immediately I could tell it was not written for my use case. [...] My use case is to use a backend process to function as a service account and batch process data. So the whole API credentials process was wrong for me.

He tried a few different approaches and finally, after some guessing, discovered how to share a sheet with the email address for the application. He then includes the steps to follow to get this same setup configured for your application and the code (using the Google_Client) to read and write to the sheet.

tagged: read write google sheets tutorial client sharing

Link: http://www.phillipshipley.com/2017/05/read-and-write-google-sheets-from-php/

SitePoint PHP Blog:
The Ultimate Guide to Deploying PHP Apps in the Cloud
May 12, 2017 @ 12:18:59

On the SitePoint PHP blog author Prosper Otemuyiwa shares what they call the ultimate guide to deploying PHP apps in the cloud with examples for Heroku, Google Cloud, IBM BlueMix, Microsoft Azure, Amazon Web Services and Laravel Forge.

There is a popular mantra amongst developers that goes like this write, test and deploy. In this tutorial, I’ll show you how to deploy your PHP apps to different cloud server platforms such as Google Cloud, Microsoft Azure, Heroku, IBM Bluemix, and others.

Cloud servers are basically virtual servers that run within a cloud computing environment. There are various benefits to hosting and deploying your applications in the cloud. [...] In fact, many companies have moved their infrastructure to the cloud in order to reduce cost and complexity. It’s a great option for small, mid-sized, and enterprise scale businesses. If you write a lot of tutorials and do POCs (Proof-of-concepts) like me, it’s also a great choice for you!

He starts off by covering the technologies that will be involved in each deploy: Linux, Apache, MySQL and of course PHP. Then, for each of the platforms previously mentioned, he goes through the setup and configuration of the same functionality. Most include screenshots of the UI in the service setting up the account and application. He also links to two tools that can make it easier to deploy your actual application to these newly configured cloud instances: Envoyer and Deployer.

tagged: guide deploy application cloud google bluemix azure aws forge

Link: https://www.sitepoint.com/ultimate-guide-deploying-php-apps-cloud/

Laravel News:
Using the Google API with Socialite
Apr 11, 2017 @ 09:47:36

On the Laravel News site there's a new tutorial posted showing you how to use the Socialite package with the Google API to connect a user's account and get a list of their contacts.

When I start a project that requires users to log in using their Google accounts, I immediately turned to Laravel Socialite. Socialite is one of Laravel’s official packages, but it is clear it only handles user authentication, making its use not as dynamic as I had hoped it would be. While I needed users to log in, I also needed to get a list of their Google Contacts. In this post, I’ll show you how I was able to query a list of contacts from Google’s People API and keep using Socialite.

They start with a basic guide to creating an application on the Google API Console and what information you'll need (credentials) to allow your application to connect. Then, using the Google API Client for PHP and the functionality built into Socialite they create the approval flow and how to handle refresh tokens should your token expire.

tagged: tutorial laravel socialite contacts google api token

Link: https://laravel-news.com/google-api-socialite

Sameer Borate:
Accessing Google Page Insights in PHP
Mar 21, 2017 @ 09:45:12

On his site today Sameer Borate shares a tutorial showing you how to access Google Insights data via your PHP application with the help of the dsentker/phpinsights package.

Google Page Insights is a required tool to have when analyzing the speed and usability of your site. As you may know these metrics influence how google ranks your page in search results. If you frequently make changes to your web site designs than it becomes mandatory to check the metrics after each change to make sure that the design changes has not affected the score in any negative way. If you have many pages to test than manual testing can quickly become cumbersome.

Thankfully there are libraries that you can use to automate this process. Once such is given in this post which allows you to get Google Page Insight metrics using PHP.

He then walks you through the installation of the package (via Composer) and how to use it, along with your Google API key, to fetch the information for a given URL. You can get information for different environments (desktop vs mobile) and even a screenshot of the page that's under test. He ends the post with a helpful hint for those that might get a certificate error when making the request and how to fix it.

tagged: google insights data tutorial package install usage

Link: http://www.codediesel.com/api/accessing-google-page-insights-php/

Twilio Blog:
Google Spreadsheets and PHP
Mar 08, 2017 @ 09:48:31

On the Twilio blog they've posted an article from Matt Stauffer looking at the combination of Google Sheets and PHP to perform some of the normal CRUD (create, read, update, delete) operations via the Google Sheets API.

Have you ever needed to pull some data from a Google Spreadsheet? My default in the past would be to export the data and upload it to the app directly, but it turns out it’s not very difficult to read directly from Google Spreadsheets using the Google Drive API.

In this tutorial, we’ll read, write, update, and delete data from a Google Spreadsheet with just a few lines of PHP.

He clones an example spreadsheet to use in the tutorial and shows how to prepare it for programatic access (basically exposing it for use). He then gets to work using the google/apiclient and asimlqt/php-google-spreadsheet-client packages to connect to and work with the API. He includes the code to:

  • connect to the API and get a usable token
  • pull data from the sheet by title
  • update individual cells data
  • updating entire rows
  • deleting rows
  • insert new rows

You'll need to be a bit familiar with how the Google API Console works to get things set up, but there's an animation that helps walk you through some of it.

tagged: google sheets tutorial package api crud operation console

Link: https://www.twilio.com/blog/2017/03/google-spreadsheets-and-php.html

SitePoint PHP Blog:
Calendar as a Service in PHP? Easy, with Google Calendar API!
Jan 26, 2017 @ 10:25:21

On the SitePoint PHP blog there's a new tutorial posted by Wern Ancheta showing you how to offer "calendar as a service" in your application with the help of the Google Calendar API. The Calendar API provides access to all of the features you'd expect from the Google Calendar system and the tutorial helps you make a fully functional overlay integrated with it and living in your application.

In this article, you’ll learn how to work with the Google Calendar API in PHP. You’ll do it by building a calendar app that allows users to add new calendars, add events, and sync calendars to Google Calendar.

The tutorial then walks you through every step of the process you'll need to get your application hooked into the API and the code to use for the integration:

  • Setting up a Google Console Project
  • Building the App
  • Configuring the App
  • Creating a Service Container for the Google Client
  • (Adding) Routes
  • Admin Route Middleware
  • Database setup
  • Home Pages creation
  • Admin Pages creation
  • Creating a Calendar
  • Creating an Event
  • Syncing a Calendar
  • Listing Events
  • Logging Out

The application they create is Laravel based and makes use of a bit of Javascript in the views for the date selector and handlebars templating.

tagged: calendar api google service tutorial laravel jquery

Link: https://www.sitepoint.com/calendar-as-a-service-in-php-easy-with-google-calendar-api/

TutsPlus.com:
Programming With Yii2: Using Ajax
Nov 10, 2016 @ 11:18:23

The TutsPlus.com site continues their series covering development with the Yii2 framework in this new article. This time they're focusing in on only the Ajax functionality using it an an example for their startup application interacting with Google Maps to place meeting locations.

In this Programming With Yii2 series, I'm guiding readers in use of the Yii2 Framework for PHP. In this tutorial, we'll explore the implementation of interactive pages using Ajax. Specifically, I'm going to highlight the use of Ajax in two areas of the Meeting Planner application, which I'm writing the Building Your Startup series about in parallel.

The article then starts in on showing you how to load a Google Map into the page using some of the built-in Ajax handling and integrating it into the "Create a Place" form. They show how to collect the information from the map once a location is selected and use this to update a "meeting" record on the backend. All coded needed to reproduce the system is included.

tagged: ajax yii2 framework programming tutorial series google map

Link: https://code.tutsplus.com/tutorials/programming-with-yii2-using-ajax--cms-26663

SitePoint PHP Blog:
2FA in Laravel with Google Authenticator – Get Secure!
Nov 01, 2016 @ 10:47:02

On the SitePoint PHP blog there's a tutorial posted from Christopher Thomas showing you how to integrate two-factor authentication into your Laravel application with a Google Authenticator-compatible library, helping to secure your site even better than just one level of authentication and authorization.

In this tutorial, we will use Laravel and Google Authenticator to demonstrate how to implement 2FA in a webapp. Google Authenticator is just one implementation of the Time-Based One-Time Password (TOTP) algorithm, RFC 6238. This industry standard is used in a lot of various 2FA solutions.

[...] How the TOTP works is that the server generates a secret key. This secret key is then passed to the user. The secret key is used in combination with the current Unix timestamp to generate a six digit number, using a keyed-hash message authentication code (HMAC) based algorithm. This six digit number is the OTP. It changes every 30 seconds.

They start with a clean slate and build a new Laravel project out and include the libraries needed for the TFA support: pragmarx/google2fa and paragonie/constant_time_encoding. You then add in the provider to Laravel's config, build out the models/tables to hold the two-factor information and add a few routes to handle the validation steps. They also include the details in building out the controllers, updating the AuthController for the new step in the authentication flow and how to handle the code validation. The code for all of this (as well as the views) is included as well as screenshots showing the setup and usage of the two-factor handling in the standard authentication flow.

tagged: tutorial google authenticator security laravel twofactor authentication

Link: https://www.sitepoint.com/2fa-in-laravel-with-google-authenticator-get-secure/

CloudWays Blog:
How To Add ReCAPTCHA To Symfony 3 Forms
Oct 05, 2016 @ 12:19:31

The Cloudways blog has a tutorial posted helping you add CAPTCHA functionality of your Symfony 3 form handling. In this case they're adding the Google reCAPTCHA handling to a registration form for users of your system.

Websites use different techniques and methods to validate contact, login and user registration forms. Some opt for custom validation methods while a large majority deploy third-party validation techniques.

Google provides a well known and proven validation tool known as reCAPTCHA. In this tutorial, I will demonstrate how to add Google reCAPTCHA to a Symfony 3 registration form. Hence, if you’re looking for a Recaptcha Symfony union, you’ve got it!

They start by helping you set up a Cloudways PHP application and install the latest version of the Symfony 3 framework on it as a sample application. They then walk you through the steps required to create a reCAPTCHA application and hooking it into your Cloudways server's hostname. With that set up they move over into the Symfony application, generating the User entity via Doctrine and creating the matching view/controller to handle the reCAPTCHA output. The registration form is then created and the handling is added to verify the CAPTCHA value submitted against the Google servers.

tagged: cloudways recaptcha symfony3 form registration tutorial google

Link: https://www.cloudways.com/blog/add-recaptcha-to-symfony-3-forms/

SitePoint PHP Blog:
Can We Use Laravel to Build a Custom Google Drive UI?
Jul 25, 2016 @ 13:57:52

The SitePoint PHP blog has posted a new tutorial that asks the question "Can We Use Laravel to Build a Custom Google Drive UI??" In this case it's a simplified version of the current Google Drive functionality, but it's more of a proof-of-concept than anything.

In this tutorial, we’re going to build an app that talks to the Google Drive API. It will have file search, upload, download and delete features. If you want to follow along, you can clone the repo from Github.

They walk you through the full process of getting the application set up, including creating the project on the Google side and grabbing the API credentials for use in your code. They then switch back over to the code side and create a basic Laravel project and configure it with the Google API credentials you just created. Next up is the creation of all of the routes for the list, upload and delete handling in the Laravel app as well as the controllers/views to make them all work. They also include search functionality, letting you easily query the API for files with names matching a certain string.

tagged: laravel google drive ui tutorial api example

Link: https://www.sitepoint.com/is-laravel-good-enough-to-power-a-custom-google-drive-ui/