Search code examples
phpgoogle-latitude

How to access the position of a contact form my google latitude account using php?


im want to execute a php script every 10 min in order to retrive the position of one of my friends on google latitude. I know how to check my position with php, but i cant find a way to track a friend.

So if you have a good tutorial or a php script, this will be help for me. Thanks!


Solution

  • this is based on the oauth libraries of the zend framework.

    <?php 
    ini_set("display_errors",1);
    error_reporting(E_ALL);
    session_start(); 
    set_include_path('/home/library/'.get_include_path());
    require_once 'Zend/Oauth/Consumer.php'; 
    
    $oauthOptions = array(
        'requestScheme'        => Zend_Oauth::REQUEST_SCHEME_HEADER,
        'version'              => '1.0',
        'consumerKey'          => 'ivana.2x.to',
        'consumerSecret'       => '*********',
        'signatureMethod'      => 'HMAC-SHA1',
        'requestTokenUrl'      => 'https://www.google.com/accounts/OAuthGetRequestToken',
        'userAuthorizationUrl' => 'https://www.google.com/latitude/apps/OAuthAuthorizeToken',
        'accessTokenUrl'       => 'https://www.google.com/accounts/OAuthGetAccessToken',
        'callbackUrl'          => 'http://ivana.2x.to/geo/?show=callback',
    );
    $consumer = new Zend_Oauth_Consumer($oauthOptions); 
    if (!isset($_SESSION['ACCESS_TOKEN_GOOGLE'])) { 
        if (!empty($_GET)) { 
            $token = $consumer->getAccessToken($_GET, unserialize($_SESSION['REQUEST_TOKEN_GOOGLE'])); 
            $_SESSION['ACCESS_TOKEN_GOOGLE'] = serialize($token); 
        } else { 
            $token = $consumer->getRequestToken(array('scope'=>'https://www.googleapis.com/auth/latitude')); 
            $_SESSION['REQUEST_TOKEN_GOOGLE'] = serialize($token); 
            $customparams = array('domain' => 'ivana.2x.to', 'granularity' => 'best', 'location' => 'current');
            $consumer->redirect($customparams ); 
            exit; 
        } 
    } else { 
        $token = unserialize($_SESSION['ACCESS_TOKEN_GOOGLE']); 
        //$_SESSION['ACCESS_TOKEN_GOOGLE'] = null; // do not use, we want to keep the access token
    } 
    $client = $token->getHttpClient($oauthOptions); 
    $client->addParameterGet('granularity','best');
    $client->setUri('https://www.googleapis.com/latitude/v1/currentLocation'); 
    $client->setMethod(Zend_Http_Client::GET); 
    
    
    $response = $client->request(); 
    $body = $response->getBody();
    header('Content-Type: ' . $response->getHeader('Content-Type')); 
    echo $response->getBody(); 
    
    • feel free to copy
    • dont use commercially without further permission
    • dont miss use - respect privacy
    • theres no guarantee for anything
    • please dont sue me.