PHP中的Google Glass用户身份验证


Google Glass User Authentication in PHP

您好。我正试图使用PHP在我的玻璃器皿中创建一个身份验证页面,作为谷歌的要求,我被困了好几天。我听从了这里的指示,但无法使其发挥作用。

这是我的代码:

<?php
    require_once('dbconnect.php');
    include_once 'google-api-php-client/src/Google_Client.php';
    include_once 'google-api-php-client/src/contrib/Google_MirrorService.php';
    include_once 'google-api-php-client/src/contrib/Google_Oauth2Service.php';
    function get_service_client()
    {
        global $service_client_id, $service_email, $app_name, $key_file_location, $browser_api_key;
        $client = new Google_Client();
        $client->setApplicationName("Google Glass"); // Set your application name
        $client->setClientId("CLIENT_ID");
        $client->setDeveloperKey("DEVELOPER_KEY");
        $key = file_get_contents("KEY_FILE_PATH");
        $cred = new Google_Auth_AssertionCredentials(
                    $service_email,
                    array('https://www.googleapis.com/auth/glass.thirdpartyauth'),
                    $key
                );
        $client->setAssertionCredentials($cred);
        return $client;
    }
    function insert_account($service,$userToken, $email)
    {
        $accountType ='info.google.glass';
        $userDataArray = array();
        $userData1 = new Google_Service_Mirror_UserData();
        $userData1->setKey('email');
        $userData1->setValue($email);
        $userDataArray[] = $userData1;
        $authTokenArray = array();
        $authToken1 = new Google_Service_Mirror_AuthToken();
        $authToken1->setAuthToken('randomtoken');
        $authToken1->setType('randomType');
        $authTokenArray[]=$authToken1;
        $postBody = new Google_Service_Mirror_Account();
        $postBody->setUserData($userDataArray);
        $postBody->setAuthTokens($authTokenArray);
        try {
            $account = $service->accounts->insert($userToken, 
                $accountType, 
                $email, 
                $postBody
            );
        } catch (Exception $e) {
            echo "fail";
        }
    }
    if (!$conn) {
        die("Connection failed: " . mysql_error());
    }
    else 
    {
        if(isset($_POST['submit']))
        {
            $tempuname =isset($_POST['uname'])?mysql_real_escape_string($_POST['uname']) : "";
            $temppass   = isset($_POST['pass'])  ? mysql_real_escape_string($_POST['pass'])  : "";
            $pass       = sha1($temppass);
            $uarray     = explode("/", $tempuname);
            //var_dump($uarray);
            $dbname     = $uarray[0];
            $uname      = mysql_real_escape_string($uarray[1]);
            $db         = mysql_select_db("genix_".$dbname);

                if($db && isset($uname)) 
                {
                    $sql    = mysql_query("SELECT * FROM users WHERE username = '".$uname."' AND password = '".$pass."'");
                    if( $sql )
                    {
                        while($row = mysql_fetch_array($sql)) 
                        {
                                $userToken      = $_SESSION['userToken'];
                                $service_client = get_service_client();
                                $mirrorService  = new Google_Service_Mirror($service_client);
                                insert_account($mirrorService, $userToken, $email);
                                $_SESSION['userToken']=null;
                                echo $row['facility'];
                        }
                    }
                else {
?>
<script>
    alert("Invalid Login.");
</script>
<?
    }
} else {
?>
<script>
    alert("Invalid Login.");
</script>
<?      
        }
    }
    // }
}

提交后我没有收到任何回复或错误。你能告诉我哪里错了吗?非常感谢。

我看到您正试图插入一个帐户。如果你还没有这样做,你将需要通过审查过程来使用这个功能。如文档中所述,您需要将您的apk上传到MyGlass以测试/使用API。