Latitude Sample application

1,090 views
Skip to first unread message

Ka-Ping Yee

unread,
Aug 9, 2010, 3:12:55 PM8/9/10
to google-la...@googlegroups.com
Hello,

To help you get started with the Google Latitude API, we've posted a sample application at:


This application is also running at:


This is a minimal application that carries out authorization and then shows your current location.

The app uses open source Python modules for OAuth written by Joe LaPenna and Leah Culver, and factors out the OAuth stuff to help you get past the OAuth dance and get started building your app.  Your application code only needs to follow the example in main.py (you shouldn't need to change oauth.py, oauth_appengine.py, or oauth_webapp.py).

Hope this helps!  Please see the project's README file for more details, and feel free to ask questions on this group.


— Ping
Google Crisis Response

Ted Gilchrist

unread,
Aug 27, 2010, 8:18:52 PM8/27/10
to google-la...@googlegroups.com

Application ID: mycrazyuncle
Server: localhost:8080
Traceback (most recent call last):
  File "/Users/egilchri/appengine/mycrazyuncle/tools/console.py", line 130, in <module>
    connect('%s:%d' % (address, port), app_id, username, password)
  File "/Users/egilchri/appengine/mycrazyuncle/tools/console.py", line 80, in connect
    app_id, '/remote_api', lambda: (username, password), server)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 482, in ConfigureRemoteApi
    debug_data=False, secure=secure)
  File "/usr/local/google_appengine/google/appengine/tools/appengine_rpc.py", line 384, in __init__
    super(HttpRpcServer, self).__init__(*args, **kwargs)
  File "/usr/local/google_appengine/google/appengine/tools/appengine_rpc.py", line 145, in __init__
    self.opener = self._GetOpener()
  File "/usr/local/google_appengine/google/appengine/tools/appengine_rpc.py", line 414, in _GetOpener
    opener.add_handler(fancy_urllib.FancyProxyHandler())
AttributeError: 'module' object has no attribute 'FancyProxyHandler'
[
--
"Speech, not just for humans"

http://www.google.com/profiles/egilchri

Ka-Ping Yee

unread,
Aug 27, 2010, 8:24:33 PM8/27/10
to google-la...@googlegroups.com
Hi Ted,

Thanks for reporting this problem!

The App Engine SDK recently changed to add fancy_urllib.  I've added fancy_urllib to the PYTHONPATH, which should fix the problem you encountered — please try pulling down the code from the http://code.google.com/p/latitudesample repository again, and giving it another try.


— Ping
Google Crisis Response

Ted Gilchrist

unread,
Aug 27, 2010, 9:04:56 PM8/27/10
to google-la...@googlegroups.com
Hi Ping,

  BTW, should the README say:

    >>> from main import OAuthConfig
    >>> Config.set('consumer_key', '<your consumer key>')
    >>> Config.set('consumer_secret', '<your consumer secret>')

instead of 

    >>> from main import OAuthConfig
    >>> OAuthConfig.set('consumer_key', '<your consumer key>')
    >>> OAuthConfig.set('consumer_secret', '<your consumer secret>')

I did this, because OAuthConfig.set wasn't working for me. Now, I'm stuck at:


because the url isn't found.

Ted

Ka-Ping Yee

unread,
Aug 27, 2010, 9:12:58 PM8/27/10
to google-la...@googlegroups.com
Hi Ted,

Yes, the README is out of date.  The configuration names and the URL were both wrong.  Sorry about that!

I have updated the README and now the instructions should be correct.


— Ping
Google Crisis Response

Ted Gilchrist

unread,
Aug 27, 2010, 9:46:11 PM8/27/10
to google-la...@googlegroups.com
Thanks. I'll see if I can get this to work. -Ted

Ted Gilchrist

unread,
Aug 28, 2010, 6:21:36 PM8/28/10
to google-la...@googlegroups.com
Hi Ping,

    Ok, I got it working. One small thing, to set the oauth secret and key, I was having trouble with the console technique, so I added the following to main.py:

class SetMyOauth(webapp.RequestHandler):
    def get(self):
        model.Config.set('oauth_consumer_key', '<your consumer key>'),
        model.Config.set('oauth_consumer_secret', 'I'<your consumer secret>''),
        self.response.out.write ("""key and secret set""")


Ted

Ka-Ping Yee

unread,
Aug 28, 2010, 6:24:12 PM8/28/10
to google-la...@googlegroups.com
Great to hear!  And thanks for the suggestion.


— Ping
Google Crisis Response

Vaishakh Thayyil

unread,
Oct 7, 2010, 2:06:04 PM10/7/10
to Google Latitude API
Hi Ka-Ping Yee,

Are there any jsp based sample application that can be deployed to
google AppEngine
to get started with just like this one to get started with ?
If anyone has any idea about it please reply .

Waiting for you reply,

Vaishakh



Ted Gilchrist

unread,
Oct 7, 2010, 2:37:53 PM10/7/10
to google-la...@googlegroups.com
BW, Ka-Ping, I have created a project on Google Code, based on some code you sent me. 


I will be doing a blog post about it soon.

Many thanks,

Ted

Alana

unread,
Oct 27, 2010, 4:41:32 PM10/27/10
to Google Latitude API
Hello Ka-Ping!

When I follow ur link http://latitudesample.appspot.com/
I am getting this message:

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

I believe this is when I have to be able to see my latitude and
longitude.
Any suggestions? Am I missing smth?

Regards,
Alana

Ka-Ping Yee

unread,
Oct 27, 2010, 7:03:59 PM10/27/10
to google-la...@googlegroups.com
On Wed, Oct 27, 2010 at 13:41, Alana <ashok...@gmail.com> wrote:
Hello Ka-Ping!

When I follow ur link http://latitudesample.appspot.com/
I am getting this message:

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

Hi Alana,

I'm not sure what is happening since the app is still working for me, but let me suggest the following.  First try going to http://google.com/latitude and signing in.  Make sure you can see your own location on the map and verify that your correct e-mail address appears in the upper-right corner.  Then, go to http://latitudesample.appspot.com/ and sign in with the same e-mail address.


—Ping
Google Crisis Response

ashoka ashoka

unread,
Oct 27, 2010, 7:58:53 PM10/27/10
to google-la...@googlegroups.com
Hi Ka-Ping!

I was not able to see my current location at http://google.com/latitude, so this what was causing an issue.
Now it works,
Thank you so much for your promt reply,
Alana

Ted Gilchrist

unread,
Jan 27, 2011, 11:14:43 PM1/27/11
to google-la...@googlegroups.com
Hi,

     This original example was very helpful. I used it to help implement my Moveable Weather, and also Moveable History mashups. However, it doesn't show how to update your current location, back  to Google Latitude. Any chance you can post sample code for that? I seem to be a little stuck.

Thanks,

Ted Gilchrist

On Mon, Aug 9, 2010 at 3:12 PM, Ka-Ping Yee <k...@google.com> wrote:

--
"Speech, not just for humans"

http://www.google.com/profiles/egilchri
about.me/ted.gilchrist

Tetsuya M

unread,
Jan 28, 2011, 6:05:08 AM1/28/11
to Google Latitude API
Hello,

I'm stack too.
I'm trying to insert the current location but get the following error.
-----
Unsupported content with type: application/x-www-form-urlencoded
-----

Error code is 400.
Looks like a headers issue but I have no idea how to solve it.
Sample code for inserting the location would be really helpful.

Regards,
Tetsuya

Ana Ulin

unread,
Jan 28, 2011, 1:07:09 PM1/28/11
to google-la...@googlegroups.com
Hi Tetsuya,

You need to set the Content-Type header field to "application/json",
if you are submitting the location in JSON format, or
"application/atom+xml" if you are using the Atom format.

Cheers,
Ana

Ted Gilchrist

unread,
Jan 28, 2011, 1:57:30 PM1/28/11
to google-la...@googlegroups.com
But the Python sample would still be great. 
Ted

Tetsuya M

unread,
Jan 29, 2011, 3:10:21 AM1/29/11
to Google Latitude API
Hi Ana,

Thanks for your advise. But I got another problem.
I set
headers={'Content-Type': 'application/json'},
in the urlfetch.fetch parameter, and it returns the "Authorization
required" error.

Tetsuya

egilchri

unread,
Feb 6, 2011, 9:45:28 AM2/6/11
to Google Latitude API
Still trying to write update_current_location, analogous to
get_current_location, which is here:

http://code.google.com/p/latitudesample/source/browse/app/latitude.py

I'm thinking the solution will appear trivial, once I see it, but I'm
still flailing away, to no avail.

Thanks,

Ted Gilchrist

Ted Gilchrist

unread,
Feb 6, 2011, 12:28:46 PM2/6/11
to Ka-Ping Yee, google-la...@googlegroups.com
Thanks Ping,

       Perhaps the reason this code sample wasn't originally provided bye the Latitude team, is that Google Latitude is normally used to get your location, not to actively update it. But I am working on an App Engine app that enables "armchair travelling", similar to what is provided here.

       So I need to perform the operation that the Google Latitude reference doc calls currentLocation.insert

       It sound like it should be dead simple, in Python, but so far, It's eluded me.

      Anyway, hopefully the Latitude team will find some spare cycles to provide a Python sample.

Thanks,

Ted

On Sun, Feb 6, 2011 at 10:20 AM, Ka-Ping Yee <k...@google.com> wrote:
Hi Ted,

Sorry, I can't tell what the issue is.  (Latitude is not my main project; I just dabbled in it to make the sample app.)  Maybe someone on the google-latitude-api group will be able to help.


—Ping
Google Crisis Response



On Sun, Feb 6, 2011 at 09:40, egilchri <egil...@gmail.com> wrote:
Hello Ping,

    I've been beating my head against the wall quite a while my next
problem. BTW, I used your sample code to write a mashup called
Moveable Weather, and it worked great. Now I'd like to write a method,
call it "update_current_location", which is like get_current_location
here:

http://code.google.com/p/latitudesample/source/browse/app/latitude.py

but is used to update my current location with data like this:

{'data': {
        'timestampMs': my_time,
        'kind':'latitude#location',
        'latitude':0.0,
         'longitude':0.0
                           }}

It seems like it should be simple, but so far it has eluded me. My
latest attempt is below, but returns a server error. Any hints or
pointer you can give would be appreciated.

Thanks,

Ted Gilchrist


   def update_current_location(self, data):
       request = oauth.OAuthRequest.from_consumer_and_token(
           self.client.get_consumer(),
           token=self.client.get_token(),
           http_method='POST',
           http_url=Latitude.REST_URL % ('currentLocation',),
           parameters={'granularity': 'best', 'body': data}
           )

       request.sign_request(
           self.client.signature_method,
           self.client.get_consumer(),
           self.client.get_token())
       returned = self.client.access_resource(request)
       content = returned.content
       status = returned.status_code
       logging.info ("Returned: %s content: %s status: %s" %
(returned, content, status))
       return returned



On Aug 9 2010, 2:12 pm, Ka-Ping Yee <k...@google.com> wrote:
> Hello,
>
> To help you get started with the Google Latitude API, we've posted a sample
> application at:
>
>    http://code.google.com/p/latitudesample
>
> This application is also running at:
>
>    http://latitudesample.appspot.com/
>
> This is a minimal application that carries out authorization and then shows
> your current location.
>
> The app uses open source Python modules for OAuth written by Joe LaPenna and
> Leah Culver, and factors out the OAuth stuff to help you get past the OAuth
> dance and get started building your app.  Your application code only needs
> to follow the example in

> shouldn't need to change oauth.py, oauth_appengine.py, or
> oauth_webapp.py).
>
> Hope this helps!  Please see the project's README

> more details, and feel free to ask questions on this group.
>
> — Ping
> Google Crisis Response

Ana Ulin

unread,
Feb 7, 2011, 2:11:05 PM2/7/11
to google-la...@googlegroups.com
Hi Ted,

What's the error that you are getting back? The example JSON you are
trying to submit is sane, so that is not the problem.

A common pitfall is that the signature is not correct, because you
forgot to put all your parameters into it before signing. Are you
using a specific OAuth library? (Is so, which?) Or are you doing the
signing by hand?

Unrelated to the problem you are seeing, but just a tip: when
submitting a currentLocation, the server will set the timestamp to the
time at which you performed the POST, so you can omit the timestampMs
field from your location JSON. (The timestamp, however, is required
when submitting historical locations.)

Cheers,
Ana

Ted Gilchrist

unread,
Feb 7, 2011, 2:37:13 PM2/7/11
to google-la...@googlegroups.com
Hi Ana,

    I'm getting a server error, htttp status code 500. Beyond that' it's kind of a mystery, since I can't see the actual server logs.

   I would reiterate my request. Can somebody at Google please take the code (originally written by Joe Lapenna), from here:


and update it to be able to accept an "insertLocation" type of operation? Then we would have both halves, the GET, to get the location, and the POST, to update it..

   Then, if they would specify exactly how to call this update_location method, using actual sample data. Do you just submit the JSON as a string, or do you url encode it, or , etc. , etc.

   The reason I ask is, there are a myriad of opportunities for this information to be "lost in translation" without an 
actual example.

    My confusion surrounds the idea of submitting JSON as "the body of the POST", as is suggested. Does this mean that the JSON, is an parameter value, and if so, what's the parameter name? And can I call Joe LaPenna's low-level code somehow, or does it need to be beefed up somehow?

    It could well be that my problems are just due to my incomplete understanding of how POST requests work. But if it is something simple, that I would think that any number of Python-literate folks on the Latitude team could whip this up in a jiffy.

   Thanks so much. I am a big fan of Google API's and products. I've got big plans for continuing my work with Latitude once I get past this roadblock.

Ted Gilchrist

Ana Ulin

unread,
Feb 7, 2011, 3:02:28 PM2/7/11
to google-la...@googlegroups.com
Ted, there is a Google API Python library, which includes a Latitude
API example for inserting current location:
http://code.google.com/p/google-api-python-client/source/browse/samples/latitude/latitude.py

This is linked from "Libraries and samples" section of the Latitude API docs:
http://code.google.com/apis/latitude/libraries.html

Cheers,
Ana

Ted Gilchrist

unread,
Feb 7, 2011, 6:10:02 PM2/7/11
to google-la...@googlegroups.com
Thanks Ana,

      While that's not based on the appengine-based latitude.py file I pointed to, I grant you that it's a working example, (or at least it will be, once I get myself set up to run it).

    So the ball is back in my court, and I thank you.

Ted

Ted Gilchrist

unread,
Feb 7, 2011, 10:18:18 PM2/7/11
to google-la...@googlegroups.com
Although I have to say, that discover API uses a whole different paradigm, which will take me a while to figure out. Too bad we can't get an example based on 


Ted

Ted Gilchrist

unread,
Feb 10, 2011, 1:47:11 PM2/10/11
to google-la...@googlegroups.com
Am now using the discovery api. Good news is, POSTs working, straight from example. Bad news is GETs don't seem to be returning my lat and lng information. 

But Joe Gregorio, of discovery api group, shows how it's working for him, so it's probably something on my end. Below, is from the mail I sent.  I'll try to figure this out on my own, unless it's immediately obvious to someone else:

-----------------------------

When I modify the sample latitude.py script, by putting this:
  print p.currentLocation().get().execute()
  print p.currentLocation().insert(body=body).execute()
  print p.currentLocation().get().execute()
I get
{u'kind': u'latitude#location'}
{u'kind': u'latitude#location', u'altitude': 35, u'longitude': -100.083389, u'latitude': 37.420352000000001, u'timestampMs': u'1297305858102', u'accuracy': 130}
{u'kind': u'latitude#location'}
So even though the second print statement really does modify my Google Latitude location, (which I can verify by just going to the Google Latitude interactive map), the 1st and 3rd aren't returning any object from which I can glean my actual current position.


Ana Ulin

unread,
Feb 10, 2011, 1:50:46 PM2/10/11
to google-la...@googlegroups.com
Make sure that you are requesting 'granularity=best' when you are
doing the GET. The API defaults to returning city-level location, and
not all location points have city-level locations corresponding to
best-available locations.

Cheers,
Ana

Ted Gilchrist

unread,
Feb 10, 2011, 2:25:14 PM2/10/11
to google-la...@googlegroups.com

So, In Latitude, I moved my avatar to San Francisco, a well-known metropolis, and it worked. I got back lat and lng. So, this works, when I am in SF.


 print p.currentLocation().get().execute()


So then I tried adding granularity="best" in various ways. This seems like how it should be:


 **  print p.currentLocation().get(granularity='best').execute()


The reason this seems right is that when I use a bogus keyword, other than "granularity", it tells me it doesn't know that parameter.


However, the result I get back, when I do ** above is


apiclient.errors.HttpError: <HttpError 401 "Invalid Credentials">


Any thoughts?

Ana Ulin

unread,
Feb 10, 2011, 2:27:33 PM2/10/11
to google-la...@googlegroups.com
On Thu, Feb 10, 2011 at 11:25 AM, Ted Gilchrist <egil...@gmail.com> wrote:
> So, In Latitude, I moved my avatar to San Francisco, a well-known
> metropolis, and it worked. I got back lat and lng. So, this works, when I am
> in SF.
>
>  print p.currentLocation().get().execute()
>
> So then I tried adding granularity="best" in various ways. This seems like
> how it should be:
>
>  **  print p.currentLocation().get(granularity='best').execute()
>
> The reason this seems right is that when I use a bogus keyword, other than
> "granularity", it tells me it doesn't know that parameter.
>
> However, the result I get back, when I do ** above is
>
> apiclient.errors.HttpError: <HttpError 401 "Invalid Credentials">
>
> Any thoughts?

When you got your OAuth token, you probably didn't ask for access to
best-available granularity, so your token is only giving you access to
city-level locations. As a result, when you request best-available
locations, you get back a 401 authorization error. You need to go back
through the OAuth flow to get yourself access to best-available
granularity.

Ted Gilchrist

unread,
Feb 10, 2011, 2:49:09 PM2/10/11
to google-la...@googlegroups.com
Bingo. Thanks. 
Reply all
Reply to author
Forward
0 new messages