2

使用示例我有这个代码。它工作正常,授权适当的范围和一切:

<?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->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(); 

不,我的问题是我得到了一个空的位置资源。它看起来像这样:

{"data":{"kind":"latitude#location"}}

数据丢失。但没有错误或任何东西。

我已登录,我的位置已设置,谷歌保证返回 lon 和 lat。

有任何想法吗?

4

1 回答 1

1

在 api 描述的指导下,我有点想念。一旦我通过了粒度参数,一切正常。我还必须使用 $client->addParameterGet('granularity','best') 添加它,因为否则 oauth 签名将不起作用。

于 2011-02-01T19:35:20.430 回答