I am trying to get a list of users from Google Spreadsheet using PHP running on Google appengine.
The strangest part is that I am using Google account login and restricted to my domain as explained in the link here.
https://developers.google.com/appengine/articles/auth
This is really awesome cause I don't have to configure anything to handle for people who do not have @mydomain.com and makes URL secure so that others cant access it.
No starts the problem. I am trying to access spreadsheet so I can get a list of users but it is not as easy as it seems. There topics about accesstoken and Oauth2.0 etc but I am not using any of those and there is no need to if you this option for user authentication.
How do I read info in a spreadsheet from this PHP file?
My app.yaml file for this file as below.
- url: /attendance/form.php
script: attendance/Form/form.php
login: required
auth_fail_action: redirect
There must be a simple way to read info from a google spreadsheet and since its is PHP I can put my username and password into, Don't see a problem with it.
I also checked out https://developers.google.com/google-apps/documents-list but it does not have code for PHP and I don't know JAVA. Any one know what to do in this situation ?
After a lot of head banging and guess work I figured it out.
Followed the instructions in here
https://github.com/google/google-api-php-client
As for install library you have to download and put "Google" folder in your code folder, so that it uploads to GAE along with your app and then include the library with the following
set_include_path(get_include_path() . PATH_SEPARATOR . 'Google/src');
Then the doc says that you need to add APP Key
$client->setDeveloperKey("YOUR_APP_KEY");
I had no idea what the APP KEY is. I keep digging into the doc and keep saying to go to the developer console. I still don't know what is an APP KEY. Now trying to wing it from the error from the browser that said invalid key setup this
That API key is what the "YOUR_APP_KEY". I really wish someone explained that to me I spent days confused and lost. It was more confusing when it said server or browser. I still don't know if I should use browser or server. It is working now so I wont trouble with it.
The getting started steps also fails to say that you need to do a require_once . I am newbie and docs need to explain step by step. I do not know what others may need but add whatever Service you need eg
require_once 'Google/Client.php';
require_once 'Google/Service/Drive.php';
The link above does not even say the different services found in it. I have to look up the file name and then open it to find out the service name. Although it looks simple after doing all this it would be nice if they were listed on the documentation link it self. I still don't know what commands I need to pull out other stuff.
Then after some mindless clicking around I found that we can find or know about the api functions by actually clicking on the in the console.
https://console.developers.google.com/project/apps~<YOURAPPID>/apiui/api/drive -- cant format it sorry
Then I cobbled up some code and ended up with help of others in stack
try{
$file = $service->files->get(FILEID);
print "Title: " . $file->getTitle();
print "Description: " . $file->getDescription();
print "MIME type: " . $file->getMimeType();
}
catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
FILEID is the long has value Google gives to each file. I figured I can test it using the online DriveAPI that allows to run querys and see what I get. I initially got error that the file was not found. It seems that I have to enable Oauth 2.0 for it to work.
As of now I got into the system and know what type of file I can see. I hope this helps any one who is trying it out for the first time. I will try to update once I can read info out of the file.
Google APIs client library is what you need: https://github.com/google/google-api-php-client