问题
I am trying to follow this link to authenticate user in GDK: https://developers.google.com/glass/develop/gdk/authentication It gives example in Java, but my webpage uses PHP. I know I have to use https://github.com/google/google-api-php-client/blob/master/src/Google/Service/Mirror.php
I am stuck with service auth page making call to mirror.accounts.insert. Not sure how to implement the service auth page. Any example would be great help.
[SOLVED] Working example is here: http://goo.gl/DVggO6
回答1:
The service auth page is the page that is opened when that user turns on your application in MyGlass. You temporarily store the userToken query param sent with that request (don't permanently store it), and then authenticate the user by whichever backend you have running. From there you then likely request the proper scope for their Google account (in this case, you need https://www.googleapis.com/auth/glass.thirdpartyauth to insert the account). Once that's done, you can create your Mirror Service as normal in PHP and then use the Accounts collection:
// $myClient would contain the typical Google_Client() setup
// See PHP quickstart for example
$myMirrorService = new Google_Service_Mirror($myClient);
// Set your inputs to insert() as needed
$accounts = $myMirrorService->accounts->insert($userToken, $accountType, $accountName, $postBody);
Keep in mind, you can only test and use this API after your APK lands on MyGlass (which happens during the review process). I would also recommend the Mirror API PHP Quickstart as a start point to understand how the authentication works if you have not done so already.
来源:https://stackoverflow.com/questions/23381012/google-glass-gdk-authentication-using-php