Otentikasi permanen Google Latitude API untuk akun tertentu (Google Latitude API permanent auth for specific account)


問題描述

Otentikasi permanen Google Latitude API untuk akun tertentu (Google Latitude API permanent auth for specific account)

I travel a lot and I had a cool idea of making a site, whereiskavi.com, to just show the city I'm in at the time. Simple, I use latitude! Or so I thought.

My research has presented me with a challenge. oauth needs to be prompted from the browser, and obviously I can't authorize every hit. Now I've used apps that don't constantly re‑prompt me for authorization, but so far the only way I've been able to do this is to acquire an oauth json string and paste it in, then wait for it to expire. This code below works, but only till an expiration date. 

My question ‑ how do I permanently authorize my app to see my account always? 

Here's my successful code, so far:

<?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>';
?>

I really just need to figure out how to have perpetual oauth sessions or something!

‑‑‑‑‑

參考解法

方法 1:

My understanding is that the token will live as long as you want it to (Ie. until you revoke it).

I've tried your code above, but am getting the following error:

Fatal error: Uncaught exception 'Google_AuthException' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }'

Even tho I have set my clientID/secret etc as configured with Google.

方法 2:

Well, folks, it seems that the API was slightly misleading for me. I've had the same access token in this for almost a month and it seems to keep renewing its self. I'll leave this question open in case anyone has more info ‑ we'll see if it lasts 2 months!

(by Kavi SiegelAdamKavi Siegel)

參考文件

  1. Google Latitude API permanent auth for specific account (CC BY‑SA 3.0/4.0)

#google-latitude #OAuth #PHP






相關問題

Otentikasi permanen Google Latitude API untuk akun tertentu (Google Latitude API permanent auth for specific account)

無法從 Google Apps 腳本連接到 Google Latitude API (Can't connect to Google Latitude API from Google Apps Script)

如何在谷歌地圖API中獲取高速公路和道路的緯度和經度 (How to get Latitude and Longitude of highways and roads in Google maps API)

如何修復谷歌地圖上的標記並移動地圖? (How to fix marker on google map and move map?)

使用 Google Latitude API 獲取朋友的位置 (Using Google Latitude API to get friends' locations)

尋找我和朋友之間最近的距離 (Finding nearest distance between me and friends)







留言討論