【问题标题】:Google Latitude API permanent auth for specific account特定帐户的 Google Latitude API 永久身份验证
【发布时间】:2012-10-17 05:40:42
【问题描述】:

我经常旅行,我有一个很酷的想法,那就是创建一个网站 whereiskavi.com,以展示我当时所在的城市。很简单,我用纬度!或者我是这么想的。

我的研究给我带来了挑战。 oauth 需要从浏览器提示,显然我不能授权每一次点击。现在我使用的应用程序不会经常重新提示我进行授权,但到目前为止,我能够做到这一点的唯一方法是获取一个 oauth json 字符串并将其粘贴,然后等待它过期.下面的代码有效,但仅在到期日之前有效。

我的问题 - 如何永久授权我的应用始终查看我的帐户?

到目前为止,这是我成功的代码:

<?php
require_once '../../src/Google_Client.php';
require_once '../../src/contrib/Google_LatitudeService.php';
require_once 'gogeocode-0.2/src/GoogleGeocode.php';

$client = new Google_Client();
$client->setClientId('0000000000000.apps.googleusercontent.com');
$client->setClientSecret('abcdefghijklmnopqrstuvwxyz');
$client->setApplicationName("whereiskavi.com");
$mapsApiKey = 'mApSApIKEy';


$access_token = '{"access_token":"CENSORSHIP_YEAH","token_type":"Bearer","expires_in":3600,"refresh_token":"THIS_MIGHT_BE_SENSITIVE DATA","created":1351291247}';
$client->setAccessToken($access_token);


$service = new Google_LatitudeService($client);
$location = $service->currentLocation->get();

$geo = new GoogleGeocode($mapsApiKey);
$result = $geo->geocode( $location['latitude'].', '.$location['longitude']);
$result = $result['Placemarks'][0];

echo '<h1>'.strtoupper($result['Locality'].', '.$result['AdministrativeArea']).'</h1>';
?>

我真的只需要弄清楚如何进行永久 oauth 会话之类的!

【问题讨论】:

    标签: php oauth google-latitude


    【解决方案1】:

    好吧,伙计们,API 似乎对我有点误导。近一个月以来,我一直在使用相同的访问令牌,并且它似乎在不断更新自己。如果有人有更多信息,我会保留这个问题 - 我们会看看它是否持续 2 个月!

    【讨论】:

      【解决方案2】:

      我的理解是,令牌将随您的意愿持续存在(即,直到您撤销它)。

      我已经尝试了上面的代码,但出现以下错误:

      致命错误:未捕获的异常“Google_AuthException”带有消息“刷新 OAuth2 令牌时出错,消息:'{“error”:“invalid_grant”}'

      即使我已经按照 Google 的配置设置了我的 clientID/secret 等。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-01-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-01
        • 1970-01-01
        • 2011-02-12
        相关资源
        最近更新 更多