PHP Classes

Offline Access to Google by Retrieving Access Tokens from a file

Recommend this page to a friend!

      PHP OAuth Library  >  PHP OAuth Library package blog  >  Google OAuth Offline ...  >  All threads  >  Offline Access to Google by...  >  (Un) Subscribe thread alerts  
Subject:Offline Access to Google by...
Summary:Use a file to retrieve and store instead of database
Messages:8
Author:Eric Lu
Date:2015-10-16 19:42:36
Update:2015-10-22 04:35:45
 

  1. Offline Access to Google by...   Reply   Report abuse  
Picture of Eric Lu Eric Lu - 2015-10-16 21:20:06
Our application already has heavy database access. I wonder whether you have php class to retrieve/store Access Token and Refresh Token from/into a file instead? Any pros and cons if I use a file for this purpose?

  2. Re: Offline Access to Google by...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-10-16 21:29:17 - In reply to message 1 from Eric Lu
What a coincidence! I just developed a sub-class to store and retrieve tokens to files. I will publish it soon.

The class uses file locking to prevent corruption caused by two scripts trying to write to update a token (for instance renewing an expired token).

The class is new so it is not yet well tested in practice. But if you use it by scripts that are not updating the same token file all the time, there is not problem with concurrent accesses.

Also if you use separate token files for different users of your application, the concurrent accesses will also practically eliminated.

Anyway, I plan to publish it and write an article about it later.

  3. Re: Offline Access to Google by...   Reply   Report abuse  
Picture of Eric Lu Eric Lu - 2015-10-16 22:26:06 - In reply to message 2 from Manuel Lemos
Good to know that you will have this soon.
Using separate token files for different users will be better and safer, I believe. I will like to try it as soon as you have it ready. Thanks!!!

  4. Re: Offline Access to Google by...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-10-18 03:49:37 - In reply to message 3 from Eric Lu
OK, I just uploaded the new sub-class that can store tokens in files.

I have been using it to access the Google WebmasterTools API v3 that requires OAuth support. So it works well offline because the class refreshes the token file automatically when it expires.

phpclasses.org/package/8487-PHP-Acc ...

  5. Re: Offline Access to Google by...   Reply   Report abuse  
Picture of Eric Lu Eric Lu - 2015-10-20 05:26:20 - In reply to message 4 from Manuel Lemos
Thanks for the quick reply!
It works well by using this new file_login_with_google.php, and also "offline access to google from file" on my Google Calendar tests.
Thank you again!


  6. Re: Offline Access to Google by...   Reply   Report abuse  
Picture of Eric Lu Eric Lu - 2015-10-21 22:17:51 - In reply to message 5 from Eric Lu
I created file_login_with_twitter.php and tried it to connect to Twitter. It works fine except there is a minor problem.
The json file it writes to always has "server":"Google" in it, even it is connecting to Twitter.

  7. Re: Offline Access to Google by...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-10-21 23:23:20 - In reply to message 6 from Eric Lu
You need to use different file names for different servers and change the server variable to Twitter.

  8. Re: Offline Access to Google by...   Reply   Report abuse  
Picture of Eric Lu Eric Lu - 2015-10-22 04:35:45 - In reply to message 7 from Manuel Lemos
I did. But It seems to be ok when I created and tried file_login_with_instagram.php. I do see the "server":"Instagram" this time. I will see whether I can find out what the problem was earlier. Thanks!