This is a simple PHP server program for upload data into Google SpreadSheet. Many pepole want to send data from small computer, such as Arduino and hopefully no charge. A few years ago, it was simple. You can just add Google User ID and password. But now, Google allows only OAuth2 authentification.
If you have a small space on your own/rental servers with PHP and MySQL environment, you can become into 'gateway to Google Spread sheet'. This server program allow to use by others.
#Installation Your work as Host are;
-
Register your Project in Google API console. Each step is described here. (https://developers.google.com/console/help/new/) If you know more detail, read (https://developers.google.com/accounts/docs/OAuth2)
-
In OAuth area, you may have Client ID, Client Secret, Redirect URL(You must specify).And you can specify Agrremtn screen contents.
-
Create database table. Database location, database name is up to you. Table definition is as follows; CREATE TABLE IF NOT EXISTS
glusers
(id
int(11) NOT NULL AUTO_INCREMENT,google_user_id
varchar(50) DEFAULT NULL,google_email
varchar(255) DEFAULT NULL,google_name
varchar(255) DEFAULT NULL,google_access_token
varchar(255) DEFAULT NULL,google_refresh_token
varchar(255) DEFAULT NULL,google_expires_in
smallint DEFAULT NULL,active_file_name
varchar(255) DEFAULT NULL,created
datetime DEFAULT NULL,used
datetime DEFAULT NULL, PRIMARY KEY (id
), UNIQUE KEYgoogle_user_id
(google_user_id
) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -
Download this package. (I don't support composer.)
-
Adjust 'config.php' constant values. LANG - 'en' or 'jp' DSN - Database environment like, 'mysql:dbname=xxxxx;host=localhost' DB_USER - database user id. DB_PASSWORD - database user password. CLIENT-ID - you got it at step2. CLIENT_SECRET - you got it at step2. CALL_BACK - you got it at steop2. SITE_URL - URL where you put these PHP programs.
-
Upload all PHP files on your server space.
-
try to access http://yourURL/gloggger/index.php
-
You can specify Google Spreadsheet name. Default is 'glogger_test'
-
Make sure $_GET['sheet'] default value in record.php.
You must make a spreadsheet. It must has two column name on the line 1. One is 'time' (case sensitive), the other one is basically 'data'. And FREEZE FIRST ROW as column name. To freeze;
- Goto the View menu.
- point Freeze Rows.
- Select one of the options. 'freeze 1 row'
By above action, Google spread sheet recognize first column as column name.
Once you register your Google account on the table by server setup programs, you can use 'record.php'
Basic format is; http://[yourURL]/glogger/record.php?email=[your registered mail address]&data=[nnnn]
Parameter email and data are required.
options: column= can change column name from data to other name as you like. sheet= can change sheet name. (Please give me good idea to change this default value. English and Japanese are diffrent.)
Enjoy !