Google谷歌纵横返回空的位置资源.这个Oauth流程有什么问题吗? [英] Google latitude returns empty location resource. Anything wrong in this Oauth flow?
问题描述
使用示例,我有这段代码.它工作正常,授权了适当的范围和所有内容:
using examples I have this code. It works fine, authorizes the proper scopes and everything:
<?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();
没有我的问题是我得到了一个空的位置资源.看起来像这样:
No my problem is that i get an empty location resource. It just looks like this:
{"data":{"kind":"latitude#location"}}
数据丢失.但没有任何错误.
The data is missing. But no error or anything.
我已登录,设置了我的位置,并且Google保证将退还lon和lat.
I am logged in and my location is set and google guarantees lon and lat to be returned.
有什么想法吗?
推荐答案
在api描述的指导下,我有点想念.一旦我通过了粒度参数,一切就可以正常工作了.我还必须使用$ client-> addParameterGet('granularity','best')将其添加,因为在其他情况下,oauth签名将不起作用.
I was a little miss guided by the api description. Once i passed the granularity parameter, everything worked fine. I also had to add it with $client->addParameterGet('granularity','best'), because oterhwise the oauth signing would not work.
这篇关于Google谷歌纵横返回空的位置资源.这个Oauth流程有什么问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!