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.

CONSUMER_KEY = “CONSUMER_KEY”
CONSUMER_SECRET = “CONSUMER_SECRET”
SIG_METHOD = gdata.auth.OAuthSignatureMethod.HMAC_SHA1
TOKEN = “GENERATED_TOKEN_FROM_PLAYGROUND”
TOKEN_SECRET = “GENERATED_TOKEN_SECRET_FROM_PLAYGROUND”

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()
client.SetOAuthToken(temp_token)
#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.

Google Earth: 2012 London Olympics

 

The 2012 Summer Olympics, to be held in London, are getting closer all the time. As they’re working hard on preparing the various venues for competition, you can use Google Earth to follow their progress.

A handful of venues already have 3D models in Google Earth, including the London Aquatics Centre (model details), seen here:

 

london-aquatics.jpg 

Another great model is the London Velodrome (model details), which will house the indoor track cycling events:

 

london-velodrome.jpg 

A great overview of the venues can be found in this Google Sightseeing post from last week. In particular, you can grab their KML file to quickly find the venues in question.

Google added fresh imagery just prior to the 2008 Beijing Olympics, as well as the 2010 Vancouver Olympics, so I expect we’ll see some great new imagery in London sometime before the games begin next summer.

Ice Cream Sandwich on the Galaxy Nexus

Beaming a video with a single tap or unlocking a device with only a smile sounds like science fiction. Now, you can actually do these things (and more) with a phone that fits in the palm of your hand.

Wednesday morning in Hong Kong—together with Samsung—we unveiled Galaxy Nexus, the first phone designed for the latest release of Android 4.0, also known as Ice Cream Sandwich.

With a super slim profile, Galaxy Nexus features a 4.65” Contour Display with true high definition (720p) resolution and a lightning-fast dual core 1.2ghz processor combined with 4G LTE or HSPA+ technology. Galaxy Nexus also features the latest in software: Ice Cream Sandwich makes Android simple and beautiful, and takes the smartphone to beyond smart.

Beauty and simplicity
With Ice Cream Sandwich, our mission was to build a mobile OS that works on both phones and tablets, and to make the power of Android enticing and intuitive. We created a new font that’s optimized for HD displays and eliminated all hardware buttons in favor of adaptable software buttons. We also dramatically improved the keyboard, made notifications more interactive and created resizable widgets.

The desktop-class browser is significantly faster, featuring a refined tab manager and the ability to sync your bookmarks with Google Chrome. Ice Cream Sandwich also features the best mobile Gmail experience to date, with a new design that lets you quickly swipe through your inbox and search messages even when you’re offline. Calendar boasts a clean new look and you can zoom into your schedule with a pinch.

Connect and share
People are at the heart of Ice Cream Sandwich. We rethought how you browse your contacts with the new People app, which combines high-resolution photos and updates from Google+ and other social services. It’s also easier to capture and share your life with family and friends. Galaxy Nexus sports a high-end camera with zero shutter lag, automatic focus, top notch low-light performance and a simple way to capture panoramic pictures. Shoot amazing photos or 1080p video, and then edit and share them directly from your phone.

Beyond smart
Galaxy Nexus isn’t just a smartphone—it’s beyond smart. Ice Cream Sandwich gives you complete control over the amount of mobile data you use by helping you better understand and manage it. We’re also introducing Android Beam, which uses near field communication (NFC) to instantly share webpages, YouTube videos, maps, directions and apps by simply tapping two phones together. Face Unlock uses state-of-the-art facial recognition technology to unlock your phone with nothing more than a smile.

This weekend marks the third birthday of the G1, the first-ever Android phone. Nine releases later, more than 550,000 Android devices are activated daily.

Starting in November, Galaxy Nexus will be available in the United States, Canada, Europe and Asia. Check out the Nexus website for a product tour and more info.

Find your perfect home with Google Fusion Tables

My husband and I were recently in the market for a new home. We worked with a realtor for a few months, looking at several houses every weekend. As we checked out each house, we tracked our thoughts about it in a Google spreadsheet, which included columns for the address, our pros and cons, individual ratings and the combined rating of the house.

One day, while my husband and I were rating a recently viewed home, he came up with a brilliant idea to put all of our home data on a map. We realized that adding geographic information to our personal opinions would help us find trends, such as which neighborhoods we preferred. A light bulb went on over my head: Google Fusion Tables!

Fusion Tables is a data management web application that makes it easy to view tabular data on a Google Map. Columns with location data, such as addresses, points, lines, or polygons, are automatically interpreted and mapped. The map features can be styled according to the data in your table. It’s also simple to share the map visualization with others.

In just a few steps, we were able to convert our spreadsheet into a fusion table:


This was a great start, but what we really wanted was to quickly get a glimpse of this data on a map. All we had to do was select ‘Visualize > Map’ from the table menu and the data in the ‘Address’ column was geocoded (i.e. converted into latitude and longitude coordinates) and the markers were displayed on the map. Clicking on the markers showed additional information about the house pulled from our spreadsheet, including the pros, cons and ratings we inputted for each location.

Our house ratings viewed in Google Maps (after being converted into a Fusion Table).
Fusion Tables also allow you to style the features on the map according to data in a numerical column in the table. We had the perfect column to use for this purpose: the ‘Total Rating’ column!

 

In order to color code the map markers by their ‘Total Rating’ score, we customized the icons based on a range of scores, with red representing the lowest scores, yellow show mid-range scores and green showing the houses with the highest combined rating. After saving these new settings, the map markers were immediately styled:


Our new map made it much easier to see what locations we were most interested in (the house just south of Redwood City) and the neighborhoods of low interest (those that were closer to the bay or hills).

We shared the map with our realtor and she loved it. It helped her refine the selection of homes she showed us and in just a matter of weeks, I’m happy to say that my husband and I found the perfect house!

Posted by Kathryn Hurley, Developer Programs Engineer, Geo DevRel

via: GoogleLatlong

The R programming language


The R programming language has become one of the standard tools for statistical data analysis and visualization, and is widely used by Google and many others. The language includes extensive support for working with vectors of integers, numerics (doubles), and many other types, but has lacked support for 64-bit integers. Romain Francois has recently uploaded the int64 package to CRAN as well as updated versions of the Rcpp and RProtobuf packages to make use of this package. Inside Google, this is important when interacting with other engineering systems such as Dremel and Protocol Buffers, where our engineers and quantitative analysts often need to read in 64-bit quantities from a datastore and perform statistical analysis inside R.

Romain has taken the approach of storing int64 vectors as S4 objects with a pair of R’s default 32-bit integers to store the high and low-order bits. Almost all of the standard arithmetic operations built into the R language have been extended to work with this new class. The design is such that the necessary bit-artihmetic is done behind the scenes in high-performance C++ code, but the higher-level R functions work transparently. This means, for example, that you can:

• Perform arithmetic operations between 64-bit operands or between int64 objects and integer or numeric types in R.
• Read and write CSV files including 64-bit values by specifying int64 as a colClasses argument to read.csv and write.csv (with int64 version 1.1).
• Load and save 64-bit types with the built-in serialization methods of R.
• Compute summary statistics of int64 vectors, such as max, min, range, sum, and the other standard R functions in the Summary Group Generic

For even higher levels of precision, there is also the venerable and powerful GNU Multiple Precision Arithmetic Library and the R GMP package on CRAN, although Romain’s new int64 package is a better fit for the 64-bit case.

We’ve had to work around the lack of 64-bit integers in R for several years at Google. And after several discussions with Romain, we were very happy to be able to fund his development of this package to solve the problem not just for us, but for the broader open-source community as well.