PHP Classes

Google Quick-start App for PHP -

Recommend this page to a friend!

      PHP OAuth Library  >  All threads  >  Google Quick-start App for PHP -  >  (Un) Subscribe thread alerts  
Subject:Google Quick-start App for PHP -
Summary:Does PHPClasses' OauthAPI support Google Identity ?
Messages:11
Author:in3novs
Date:2015-05-29 09:44:25
 
  1 - 10   11 - 11  

  1. Google Quick-start App for PHP -   Reply   Report abuse  
Picture of in3novs in3novs - 2015-05-29 09:44:25
Hi, I am new on Oauth,

I am a Blogger author that used to manage my posts using the Zend API via legacy client-login.

Now the Google's Blogger legacy Zend APi is deprecated. And I need to rewrite my old Blogger interfaces to Zend .. :(

I had a look at PHPClasses' OauthAPI. It is (very) interesting, but as I understand, the current version only allows the redirect URL on public domain, even for Google API.

---

However, on May 28th Google updated an article with a sample to show ho identify the user on a LOCALHOST server.
This is possible By using the Google's identity toolkit

Here is the instructions:
developers.google.com/identity/tool ...

I tried the Google QuickStart sample, and yes, it works. I can be identified. And I needed 3 days only to have the testing code working... :-(

Despite the time spent, I still do not understand what to do after that, what to do to control my Blog using my PHP scripts !

---

my questions:


1) Is it planed to update the PHPClasses's Oauth-Api to manage the identity using localhost ?
-- As a blogger author, that would allow me to obtain the "token" and so on, by using the integrated PHP-4a server

2) Is it possible to have some sample on how to use the PHPClasses'Oauth process and how to use authenticaton data to access Google API, like Blogger ?

Many thanks in advance to Manuel :)


  2. Re: Google Quick-start App for PHP -   Reply   Report abuse  
Picture of in3novs in3novs - 2015-05-29 09:53:20 - In reply to message 1 from in3novs
The PHP version is PHP-5.4 and later, of course (I typed "PHP-4a")
It includes the built-in server to run the Google's QuickStart demonstration.

  3. Re: Google Quick-start App for PHP -   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-05-29 17:09:17 - In reply to message 1 from in3novs
The restriction of the redirect URL to be on a public domain is from Google, not from the class.

If they now accept localhost, I was not aware of that. But then this class should work with localhost.

There are several examples to work with Google APIs. Try for instance the login_with_google.php example script.

phpclasses.org/package/7700-PHP-Aut ...

You just need to change the CallAPI function call to call Blogger APIs.

  4. Re: Google Quick-start App for PHP -   Reply   Report abuse  
Picture of in3novs in3novs - 2015-05-29 20:53:02 - In reply to message 3 from Manuel Lemos
Confirmed, it works with localhost :-)

1) In google credentials, create a Client ID for web application providing as parameters
localhost:8080

localhost:8080/<path-to login_with_google>.php

2) Adjust the require to http.php and the client_id/client_secret
in the file login_with_google.php

3) Start the localhost built-in server
S:> php.exe -S localhost:8080 -t <dirname-of-login_with_google.php>


_________

And the result is :

localhost:8080/Oauth/login_with_goo ...


"
you have logged in successfully with Google!

stdClass Object
(
[id] => 1142203625xxxxx
[email] => in3novs@xxxxx
[verified_email] => 1
[name] =>
[given_name] =>
[family_name] =>
[picture] => ?????????.jpg
[locale] => en
)

"

Don't know what to do with that, but i confirm it works :)

_____

BTW, I found an old sample about how to post on Blogger
gayanonline.blogspot.fr/2013/03/goo ...

The require'd files are not the same, but the logic is Blogger v3


Thanks again, i will continue to test.



  5. Re: Google Quick-start App for PHP -   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-05-30 05:17:36 - In reply to message 4 from in3novs
In the login_with_google.php there is a call to CallAPI function. Change the URL and parameters to whatever is the Blogger API call you want to make.

  6. Re: Google Quick-start App for PHP -   Reply   Report abuse  
Picture of in3novs in3novs - 2015-05-31 20:04:27 - In reply to message 5 from Manuel Lemos
Yes, I am using it.
BTW, in login_with_google.php, scopes are deprecated, and the test does not worked well.

$client->scope = 'https://www.googleapis.com/auth/userinfo.email'.
'https://www.googleapis.com

Google requires now :
googleapis.com/auth/plus.me

(Well, it works, but I don't see how to get the email)


=====
For Blogger, we can use something like this

// SCOPES
$SCOPE_BLOGGER = 'https://www.googleapis.com/auth/blogger';
$SCOPE_GDRIVE = 'https://www.googleapis.com/auth/drive';
$SCOPE_PLUSME = 'https://www.googleapis.com/auth/plus.me';

// !Attention: PHPCLasses uses SPC separated list !
$OAUTH_SCOPES = array($SCOPE_BLOGGER, $SCOPE_GDRIVE, $SCOPE_PLUSME);

$client->scope = implode(' ', $OAUTH_SCOPES);

  7. Re: Google Quick-start App for PHP -   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-06-01 03:40:24 - In reply to message 6 from in3novs
I tried it here and it worked well. The client scope must be this way separated by spaces. You do not need any Google+ scope to get the user profile and email. I don't

'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'

According to this page you just need to add the scope https://www.googleapis.com/auth/blogger . I do not see any requirement using Google Drive or Google Plus scopes to access Blogger API. It would not make sense.

developers.google.com/blogger/docs/ ...

  8. Re: Google Quick-start App for PHP -   Reply   Report abuse  
Picture of in3novs in3novs - 2015-06-01 15:23:54 - In reply to message 7 from Manuel Lemos
((I posted yesterday night a long post but it doesn't appear ? )

I believe the multiple scopes are intended to avoid requesting multiple time the access_token. Otherwise, client would require 2 oauth process for each service. In my case I use Drive as a storage for my blog.

If you say the info_email/user profile scopes work, I probably did a wrong configuration of my machine.


As I said in my (lost) posting, my main problems was to manage acess-token/refresh_token. Since your Class manage the refresh token, I solved the goal by:

-1- creating a storage_oauth_client_class using as model the cookie_oauth_client. Instead of serialize in a cookie, I simply save and read the access_token to my drive ;

-2- following the instructions related to CheckAccessToken
phpclasses.org/blog/package/7700/po ...

For now, it works !

I will start working with the api calls soon, but syntax is straightforward (as described in the REST commands).
I need to develop some basic CRUD management and everything will be done.

I think my major issue is solved.
Again, I want to thank you for your excellent class and for your feed-back !



  9. Re: Google Quick-start App for PHP -   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-06-01 20:19:15 - In reply to message 8 from in3novs
If you start requesting just a few scopes and then change the scopes variable, that will not affect the scopes allowed to the already retrieved scopes.

You need to start over to get a new token with the right scopes, probably calling first ResetAccessToken so the class can "forget" the previously requested token.

  10. Re: Google Quick-start App for PHP -   Reply   Report abuse  
Picture of steve chapman steve chapman - 2015-10-01 17:45:55 - In reply to message 8 from in3novs
I am also having difficulty implementing oauth2 to post to blogger. You mention that you got it to work. Can you share your code showing the final results of your discussion? Thanks.

 
  1 - 10   11 - 11