0

我想每 10 分钟执行一次 php 脚本,以检索我的一位朋友在谷歌纬度上的位置。我知道如何用 php 检查我的位置,但我找不到跟踪朋友的方法。

因此,如果您有一个好的教程或 php 脚本,这将对我有所帮助。谢谢!

4

1 回答 1

1

这是基于 zend 框架的 oauth 库。

<?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(); 
  • 随意复制
  • 未经进一步许可,请勿用于商业用途
  • 不要错过使用 - 尊重隐私
  • 没有任何保证
  • 请不要起诉我。
于 2011-04-02T16:43:19.920 回答