0

I have used the Python Starter project, and I can add time line cards that then show up on my Glass.

What I would like to do is call the endpoints from a standalone application running on my Mac to trigger the Python logic to insert entries into the timeline.

Any ideas on where I should start?

Edit: Not sure why this was down voted. I basically wanted to insert cards to my time line from Objective C. After digging around for a while, I was able to figure this out using the Objective C libraries that Google provides for interacting with their services.

Beebunny
  • 4,190
  • 4
  • 24
  • 37

1 Answers1

1

Your code which inserts the timeline items will be largely the same, but you will need to use a different flow to acquire your access token. You probably want to use the OAuth 2.0 flow for installed applications which is also document in the Python API Client Library docs.

Your Glassware might work something like this:

  1. Create a new flow

    from oauth2client.client import OAuth2WebServerFlow 
    ... 
    flow = OAuth2WebServerFlow(client_id='your_client_id',
                       client_secret='your_client_secret',
                       scope='https://www.googleapis.com/auth/glass.timeline',
                       redirect_uri='urn:ietf:wg:oauth:2.0:oob')
    
  2. Create an Auth URL and instruct the user to access it in a web browser

    auth_uri = flow.step1_get_authorize_url()
    print 'Please navigate here ' + auth_uri
    

    This will yield a code. Have the user paste that code to you.

  3. Exchange the code for a credentials

    credentials = flow.step2_exchange(code) 
    
  4. Store those credentials for later use in a file, database, or some other persistent storage. This is how you'll insert items into your user's timeline.

  5. Using the credentials, insert an item into their timeline

    http = httplib2.Http()
    http = credentials.authorize(http)
    
    mirror_service = build("mirror", "v1", http=http)
    body = {
        'notification': {'level': 'DEFAULT'},
        'text':'Hello world!'
    }
    
    timeline_item = mirror_service.timeline().insert(body=body).execute()
    
mimming
  • 13,974
  • 3
  • 45
  • 74
  • Jenny - I think this helps, but I'm actually trying to do something different. As a matter of fact, I am trying to call my Python Mirror API from an Objective C application. I can see in main_handler.py that the post method has an annotation (@util.auth_required). – Beebunny Jan 13 '14 at 23:46
  • What I am essentially trying to do is make a post request to my app i.e. myapp.appspot.com and feed it the proper value for the POST variable "operation". – Beebunny Jan 13 '14 at 23:47
  • @util.auth_required is the oauth decorator. It's a feature of the Google Python API client library that automates some parts of the OAuth flow. But I'm curious, are you actually executing Python in your Objective C application, or just trying to learn how to implement it in Objective C? – mimming Jan 13 '14 at 23:47
  • Jenny, if I remove @util.auth_required from the post or get method and deploy, I get a 500 Internal Server error when I go to my app. – Beebunny Jan 13 '14 at 23:49
  • Jenny, the Python and Objective C are completely separate in my application flow. I just want to make a POST request from Objective C to my Python starter project (hosted on Google App Engine) to add a card to the timeline. – Beebunny Jan 13 '14 at 23:51
  • 1
    Ah now I understand. It sounds like a pretty complex application. You won't be able to use the decorator, but you still need credentials to make a request. When you make the POST from your Objective C app you will need to include some kind of identifier about the identity of the user. Then, on your web server, use this identifier to recall credentials for that user which you previously stored from the OAuth flow. Finally, use those credentials to create the mirror_service object as described in my answer. – mimming Jan 14 '14 at 00:19