What?
This is an article explaining the code needed to write a PHP script which generates an access token for a service account which in turn is used to list files in a team's Google Drive.

This is very different to my code for OAuth when attended: Google Authentication - OAuth 2.0 using PHP/cURL... In that this one doesn't prompt for a user. Again this script doesn't need the client libraries, composer, vendor, etc.

Why?
This took me the best part of a month to get working. It is taken from Google's documentation as well as other forums and websites that try to explain it. Do not waste your time like I did on the public key, verifying a JWT signature, or including any third-party libraries. You can do it in pure PHP and all you need is the JSON key that you generated in your Google console.

Applies to:
  • Google Drive REST API v3
  • Google OAuth 2.0 v4
  • Google Cloud Platform IAM
  • Google Suite
  • PHP v5.6.35

How?
I'm going to go through each section of the code to go through the logic and highlight any changes you may need to make.

What?
A super quick article to show how to link to the thumbnail image of a Google Drive file, in this case a video file.

How?
The hardest part of this is to get the Google Drive File ID (which you need for the below). The image link (src) will be as below but then this is a redirect to the actual thumbnail stored by Google Drive:
copyraw
https://drive.google.com/thumbnail?authuser=0&sz=w320&id=<GOOGLE_DRIVE_FILE_ID>

// where <GOOGLE_DRIVE_FILE_ID> is the file id
  1.  https://drive.google.com/thumbnail?authuser=0&sz=w320&id=<GOOGLE_DRIVE_FILE_ID> 
  2.   
  3.  // where <GOOGLE_DRIVE_FILE_ID> is the file id 
Category: Google :: Article: 654

What?
This is an article which lists the functions necessary to process Google Authentication using OAuth2.0. These functions allow a script to simply be loaded and to either create a token file, or use the existing one as long as it hasn't expired.

Update 2019
This script requires a user to authenticate the google account. I have a newer article called Google Drive API v3 - OAuth2 using Service Account in PHP/JWT documenting a script which accesses a Google Drive using a Service Account (unattended).

Why?
This is a big cop-out as I simply took someone else's functions and upgraded them to use the mentioned token based authentication. I find myself going through the motion and designing on a per-app basis so I wanted a standard way of doing it and I'll update this article as I improve on the code.

How?

What?
So this is supposed to be a quick article detailing how I used a PHP function to upload a video file to Google Drive. Note that this example does not involve installing the Google Client Library for PHP. So no classes or built-in functions that you didn't write or know what they're doing.

Why?
The objective here is to upload a video file to my Google Drive. This assumes you have already "Enabled the Drive API" via your Google Developers console as well as gotten your OAuth 2.0 access/refresh tokens and specified the appropriate scopes.

The scopes I chose were to do with getting a working example rather than the recommended scope, though you may only need the first (untested):
copyraw
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile
  1.  https://www.googleapis.com/auth/drive.file 
  2.  https://www.googleapis.com/auth/userinfo.email 
  3.  https://www.googleapis.com/auth/userinfo.profile 

How?
I've listed below 3 methods, the first follows the manual (or the logic thereof as I don't use the client library) and is a function sending two requests, the second is the appropriate multipart function which uploads and names the file in a single request, and the third is a 'nice-to-have' upload to the specified folder.
Category: Google :: Article: 649

What?
A reference to what size an image background should be set to for various screen sizes.

Why?
A background image I was using was unedited at 1600x2133 (364kb) and was not displaying on smaller devices. Configuring drawables for each layout seemed to be the only solution.

copyraw
res/drawable-ldpi      240x320
res/drawable-mdpi      320x480
res/drawable-hdpi      480x800
res/drawable-xhdpi     640x960
res/drawable-xxhdpi    960x1440
res/drawable-xxxhdpi   // for launcher only 640dpi
res/drawable-tvdpi     1.33*mdpi // not needed as mdpi or hdpi is used
  1.  res/drawable-ldpi      240x320 
  2.  res/drawable-mdpi      320x480 
  3.  res/drawable-hdpi      480x800 
  4.  res/drawable-xhdpi     640x960 
  5.  res/drawable-xxhdpi    960x1440 
  6.  res/drawable-xxxhdpi   // for launcher only 640dpi 
  7.  res/drawable-tvdpi     1.33*mdpi // not needed as mdpi or hdpi is used 

Category: AndroidOS :: Article: 598

Applies to:
  • Android Studio (Beta) 0.8.9
  • Android Google Maps v2

What?
A sequel to my article "Basic Android App using Google Maps and Current Location", this article suggests how to add Map as a sub activity. Note that this article is based on a new blank project which does not include code from the previous example but you can still build this over the previous example (as I did).

Why?
The previous article meant that the Google map was your main activity and any other activity would be a sub-activity; returning to the map activity would restart the app as a menu item, it would need to launch a new intent... I wanted to change my previous example so that the homepage of the app (the starting page) will simply display a button to the map (in case of offline mode or incompatibility with the device).

How?
In this example, I'm going to add the map as a fragment. This is the most rudimentary example (display map, move camera and display marker) and can be run from any other activity:

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: The information on this website is provided without warranty and any content is merely the opinion of the author. Please try to test in development environments prior to adapting them to your production environments. The articles are written in good faith and, at the time of print, are working examples used in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Joes Word Cloud

version   find   select   uploaded   windows   search   following   database   need   work   page   google   display   time   table   first   list   script   files   program   data   could   creator   report   user   code   error   name   source   parameter   date   file   mysql   website   using   note   server   joomla   solution   function   order   would   zoho   license   value   used   form   system   where   added   JoelLipman.Com

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.