Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Forgive me if I'm missing something, but how do you know what Google account to link them with if you don't have their email address? Usually, you'd prompt the user to enter their Google Account's email in order to find their profile in the first place.</p> <p>Using OAuth2, you can request permissions through the <code>scope</code> parameter. (<a href="http://code.google.com/apis/accounts/docs/OAuth2Login.html#scopeparameter" rel="nofollow">Documentation.</a>) I imagine the scopes you want are <code>https://www.googleapis.com/auth/userinfo.email</code> and <code>https://www.googleapis.com/auth/userinfo.profile</code>.</p> <p>Then, it's a simple matter to <a href="http://code.google.com/apis/accounts/docs/OAuth2Login.html#userinfocall" rel="nofollow">get the profile info</a> once you've obtained your access token. (I assume you've been able to redeem the returned authorization code for an access token?) Just make a get request to <code>https://www.googleapis.com/oauth2/v1/userinfo?access_token={accessToken}</code>, which returns a JSON array of profile data, including email:</p> <pre><code>{ "id": "00000000000000", "email": "fred.example@gmail.com", "verified_email": true, "name": "Fred Example", "given_name": "Fred", "family_name": "Example", "picture": "https://lh5.googleusercontent.com/-2Sv-4bBMLLA/AAAAAAAAAAI/AAAAAAAAABo/bEG4kI2mG0I/photo.jpg", "gender": "male", "locale": "en-US" } </code></pre> <p><strike>There's got to be a method in the PHP library to make that request, but I can't find it.</strike> No guarantees, but try this:</p> <pre><code>$url = "https://www.googleapis.com/oauth2/v1/userinfo"; $request = apiClient::$io-&gt;makeRequest($client-&gt;sign(new apiHttpRequest($url, 'GET'))); if ((int)$request-&gt;getResponseHttpCode() == 200) { $response = $request-&gt;getResponseBody(); $decodedResponse = json_decode($response, true); //process user info } else { $response = $request-&gt;getResponseBody(); $decodedResponse = json_decode($response, true); if ($decodedResponse != $response &amp;&amp; $decodedResponse != null &amp;&amp; $decodedResponse['error']) { $response = $decodedResponse['error']; } } } </code></pre> <hr> <p>Anyway, in the code you posted, just pass the desired scope to <code>createAuthUrl()</code>:</p> <pre><code>else { $authUrl = $client-&gt;createAuthUrl("https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"); print "&lt;a class='login' href='$authUrl'&gt;Connect Me!&lt;/a&gt;"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload