2011-04-02 15 views

回答

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(); 
  • 隨意複製
  • 不用於商業用途沒有進一步的許可
  • 不要錯過使用 - 尊重他人的隱私
  • 世界上沒有保證任何東西
  • 請不要告我。
+1

「請不要起訴我」 HAHAH有趣的傢伙:對 – Kyle 2011-04-02 16:45:54

+0

不,我的意思吧XD – 2011-04-02 16:48:11

+0

棘手的部分是通過粒度參數,至少在我寫這篇文章的時候它不是任何地方和響應記錄只是空着,其他的一切都是正確的。它不是可選的,並且沒有默認值。 – 2011-04-02 16:50:03

相關問題