OAuth 1.0 Tokens with the Python Client Library


The OAuth Playground is a great tool to learn how the OAuth flow works. But at the same time it can be used to generate a “long-lived” access token that can be stored, and used later by applications to access data through calls to APIs. These tokens can be used to make command line tools or to run batch jobs.

In this example, I will be using this token and making calls to the Google Provisioning API using the Python client library for Google Data APIs. But the following method can be used for any of the Google Data APIs. This method requires the token is pushed on the token_store, which is list of all the tokens that get generated in the process of using Python client libraries. In general, the library takes care of it. But in cases where it’s easier to request a token out of band, it can be a useful technique.

Step 1: Generate an Access token using the OAuth Playground.
Go through the following process on the OAuth Playground interface:

  • Choose scope(s) of every API you want to use in your application (https://apps-apis.google.com/a/feeds/user/ for the Provisioning API) . Here you can also add scopes which are not visible in the list.
  • Choose an encryption method that is the signature method to encode your consumer credentials. (“HMAC-SHA1” is the most common)
  • Enter your consumer_key and consumer_secret in the respective text fields. The consumer_key identifies your domain and is unique to each domain.

After entering all the required details you need to press these buttons on the OAuth Playground in sequence:

  • Request token: This will call Google’s OAuth server to issue you a request token.
  • Authorize: This will then redirect you to the authorization URL where you can authorize or deny access. At this point if you deny the access you will not be able to generate the Access token. Accepting this will convert the Request token generated in the last step into an Authorized Request token.
  • Access token: Finally, this step will exchange the authorized Request token for an Access token.

After the last step the text field captioned auth_token in the OAuth Playground has the required Access token and that captioned access_token_secret has the corresponding token secret to be used later.

Step 2: Use the above token when making calls to the API using a Python Client Library.

Here is an example in Python which uses the OAuth access token that was generated from OAuth Playground to retrieve data for a user.

SIG_METHOD = gdata.auth.OAuthSignatureMethod.HMAC_SHA1

DOMAIN = “your_domain”

client = gdata.apps.service.AppsService(source=”app”, domain=DOMAIN)
client.SetOAuthInputParameters(SIG_METHOD, CONSUMER_KEY, consumer_secret=CONSUMER_SECRET)
temp_token = gdata.auth.OAuthToken(key=TOKEN, secret=TOKEN_SECRET);
temp_token.oauth_input_params = client.GetOAuthInputParameters()
#Make the API calls
user_info = client.RetrieveUser(“username”)

It is important to explicitly set the input parameters as shown above. Whenever you call SetOuthToken it creates a new token and pushes it into the token_store. That becomes the current token. Even if you call SetOauthToken and SetOAuthInputParameters back to back, it won’t set the input params for the token you set.

Meet the SketchUp Sages: Gaieus

If you’ve ever stopped by the SketchUp forums to ask a question, chances are you got an answer from one of the “SketchUp Sages”. Today, we are kicking off a blog post series profiling these SketchUp ninjas. In this inaugural installment, we’re excited to introduce a Hungarian sage by the name of Csaba Pozsarko, though you’ll see him in the forums as “Gaieus”. Like any frequent contributor to the forums, Gaieus had a lot to say, and as as a preeminent sage, his words are wise. Be sure to stop by and visit him in the community if you’d like to learn more.

Gaieus visited the Boulder team from Hungary this year for the 2010 3D Basecamp.

What do you do for a living?

I am an archaeologist by trade, but I now try to model archaeological reconstructions (also) for a living – at least as much as possible. Of course, I do other modeling jobs as well. One does not reject paid jobs on the ground that they are not at least 300 years old.

Then there is SketchUcation where – beside the forums or The Daily CatchUp – we are working hard to launch some new and exciting stuff. However, if I told more now, I am sure my friend, and general director, Mike Lucey would kick me in the rear. Stay tuned…

Roman watchtower on the Pannonian lines

How long have you been using SketchUp? / What’s the first version you used?

I started using SketchUp shortly after version 5 was made free by Google…some time around mid-2006. I hadn’t heard about it previously, although I had already been involved in 3D visualization of archaeological sites half a decade before. I worked with five other European partners on the “Peregrinus Project” that we made of Ancient Roman archaeological sites (three of them part of the World Heritage).

One day, I was browsing on Google Earth and happened on a 3D building somewhere I can no longer remember. They were rare back then, and in the Google Earth bubble, there was a link to SketchUp. When I discovered there was a free version to start with, I was sold and never looked back.

I most probably would not have plunged into it if there hadn’t been the free version. In my opinion, the 8 hours (still valid for the Pro version) is not enough for one to get the real feeling of it. I can only thank Google for that free version, but that was just the bait. I later bought Pro.

Do you use SketchUp in your career?

Yes. Beside some occasional translation work or tour guiding around our World Heritage site, I currently only do SketchUp related work for living. When I am at an archaeological excavation, I am already looking at the ruins thinking, “how could I build them in Sketchup?”

Medieval houses from the 17th century

What are your hobbies, both online an offline? Do you somehow involve SketchUp in these?

SketchUp? :-)

Well, maybe teaching. Not necessarily face-to-face or even online training courses but I create informative materials. Maybe this sounds boring, but how about if I put this way: currently I am dreaming of and working on interactively visualising the historic phases of my city in 3D, starting with the Roman Empire and maybe ending with the late 19th century industrial boom.

Now imagine this provided kids the ability to learn their local heritage online. Nowadays, they are occupied with those strategy or FPS games, but in this case, they could also learn from it. Maybe I am still a child myself and dreaming.

Do you build or have you built any SketchUp Ruby Scripts? / API based add-ons? / Dynamic Components?
Well, my background is history, archaeology, and maybe law (I am also a lawyer), so I have never been a technically oriented person. Whatever I cannot see with my eyes when creating it is not of much interest to me. However, I have built some very simple Dynamic Components. When I model “professionally,” I do archaeological reconstructions. Dynamic Components are not too useful since my models are always unique. Of course, I fully understand its use when it comes to product or construction parts manufacturers and developers.

There are so many talented and generous ruby scripters out there that it would be a waste of resources to start playing with it and keep hindering them in their work with my basic questions. I, more or less, see what’s going on in a ruby file and modify it to my needs.

The Google Earth plugin is different; I have ideas about where and how I would like to implement it. I also have some basic knowledge of website development, so lately I have started to play around the Google Earth API (as it is also required for becoming a Google Qualified Geo 3D Developer) as well as studying the kml documentation, but I will never be a real coder.

What plugins do you use? What is your favorite?

You should see my plugins folder. There are 246 items (out of which 44 are sub-folders)! I have to scroll my Plugins menu on my 22” monitor and that’s just the Plugins menu – how about the Tools, the Camera, the Draw menu or the Context menu? I even have plugins in my File menu. Which one are you interested in? :-)

Maybe a bit more seriously… Yes, I have lots of plugins but they are for all sorts of different tasks, and sometimes I do not use one for weeks or months. As for a favorite? Well, in light of the above, it would be really hard to say anything.

As an example: when I had to model a bunch of arches, I used thomthom’s UV Toolkit a lot to texture them. Then, that was my favorite. When I have to engrave some 3D text into a curved shape, I “bend it like Fullmer”. When I had to adjust the roof to an irregular Roman horreum (granary), I used the sheer function of Fredo6’s FredoScale. If I need to render section cuts in an external renderer, I use TIG’s SectionCutFace and Whaat’s Zorro2 plugins.

But there are so many. This is of course a bit unfair with the rest (240?) of those wonderful plugins and plugin writers who are now left out of my quick list here.

14th century Carmelite church

Do you use any other software alongside SketchUp?

My main modeling platform is SketchUp of course. However, sometimes one cannot avoid using other things as well. There are some organic modeling tools like Sculptris or third party rendering or composing software like Twilight, Thea, Simlab Composer, or the free but excellent Kerkythea and others. I have a couple of tree generating applications (for less poly-sensitive programs of course) like tree(d). There are different applications to convert file formats from/to each other like Meshlab, and of course, I use a bunch of image editors for all kinds of post processing – shader creation, batch processing, video editing or even just for viewing.

Lately, I am getting more and more interested in displaying 3D content on the web. The Google Earth and the Google Earth Plugin would be one way. However “Your World in 3D” does not “represent actual structures” so Google Earth – for the time being – is not the right solution. There are other cool apps like 3dvia or Unity3D that display your 3D world on the Internet.

What communities do you participate in? Are they all specific to or relating to SketchUp?

The two most important ones are the SketchUcation Community Forums (where I am also a forum administrator) and the official Google SketchUp Help Forum (where I am a Top Contributor – or “SketchUp Sage”). I visit these forums every day – or more precisely, whenever I work from home, I am practically online on both in one of my browser tabs.

Then there are some I am subscribed to and lurk around like the 3D Warehouse Forum, the Google Earth Help Forum, or TaffGoch’s incredible Geodesic Help Group.

Some other ones I regularly visit and participate in are mainly also related to SketchUp forums of third party applications I use and such. On some I only lurk as a beginner while I am more experienced with other programs and participate more actively myself.

Roman basilica from the 4th century

What is one of the most rewarding experiences you’ve had as a Top Contributor?

I can’t really pick one. It is always rewarding when someone finally understands a tricky thing in SketchUp or when a “newbie” finally has that breakthrough moment and becomes part of the “Anonym SketchUholics’ Club”. And of course, being invited to two consecutive 3D BaseCamps, meeting all the SU folks and many users I know from the online communities was something very special that I will always remember.

Why do you participate in the SketchUp community?

Because I am a selfish, avid and lustful person and I want that rewarding feeling above every day. 😉

More seriously: I don’t know. By now, it is also my “job” and daily routine. When I was a newbie, I was far from being able to do what I planned. I learned a lot on the old be @Last Forums. Don’t get me wrong; SketchUp has an exceptionally good help documentation and used to have back then as well. But often, beside the “how-to’s”, you also want to know the “why’s” and all these things can only be picked up in a community. So now it’s kind of time to give something back to the same community (where only the members change).

Do you use any other sites?

Well, there are two different things here. Sites that I use for myself – apart from “working” on them of course – mainly good CG texture collections, the 3D Warehouse (although I tend to model almost everything for my own models) and the help forums of other 3rd party applications.

Then there are sites, tutorials, videos (and let’s not forget the SketchUp Help Center), etc. that I visit to pick up links for others to better understand what I want to explain. The reference system of the SketchUp Help Forum is extremely useful, so in the course of hanging around there it’s more or less sufficient. I would still highlight one that is often overlooked: the SketchUp Sage site, which is an extremely rich collection of everything SketchUp related, maintained by our Top Contributor SketchUp Sage, catamouintain.

Do you have a favorite modeler? A favorite style?

Hm. This is a question just like my favorite plugin or most rewarding experience. But I’ll pick one of the many: Aerilius. He does an amazing job with not only modeling and rendering archaeological reconstructions but also with visualizing them both with 3D panoramas and on Google Earth (beside the “representation of the actual structures”) with interactive tours around the reconstructed models. Just two examples: the Roman Villa at the Weilberg – “now” and “then” or the Limburg Monastery (also in the panoramas above) “now” and “then”. Also, he is a “supermodeler” and has the same endeavor as me – that Google Earth will finally incorporate 3D content of no longer existent, archaeological reconstructions. I can hardly wait for him to become a Top Contributor and SketchUp Sage (which he is even without the badge). I guess by the time this interview is released, he will already have become one of us.

A favorite style? If this is about SketchUp Styles, maybe Dave Richards makes the best use of them. As he is a woodworker, he probably makes more use of the sketchy styles than a landscape designer would.

Bauhaus house from the 30’s

What is the most fun thing to do in SketchUp?

Modeling. Just doodle around without any particular purpose and try out different things that you may never do otherwise. This is also good for learning, especially for beginners. It is always important not to mess up their “real” models and projects with some experimentation. But then it is also fun when you are doing modeling on a real project. To see the model growing in front of you and to enjoy the real time experience while doing it. This is when you “knead the dough”. Then put it into the oven and see it being baked in a photo-realistic renderer, and you get the yummiest thing in the world!

If you could plant one idea in the mind of any new SketchUp user, what would it be? (This is your chance to educate a user before they start using the forum!)

Practice before you model “live”. Read the documentation and re-read the documentation. What my friend and moderator on the forums has in his signature (if I may): “The average user never reads user guides and tutorials, that’s why they are only average”. Go to the forums if you get stuck and ask.

Asking is free and the ones who take their time to constantly be there as helpers, really mean to help. And when you ask, try to be as clear and as specific to your problem as possible but only as far as SketchUp and the modeling part is concerned – do not bring in too much unrelated, special stuff. Also, if possible, provide images, upload your model so that others can figure out what you are talking about even is you are not 100% familiar with the correct terms. But questions like “How to make a car” will most probably never be fully answered. However, the most important thing is to enjoy what you are doing! SketchUp lets you do that so allow it to help you.

See more of Gaieus’s beautiful work here.