Showing posts with label from. Show all posts
Showing posts with label from. Show all posts

Monday, March 9, 2015

Using OAuth 1 0 Long Lived Tokens from OAuth Playground 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.

Other Practices:

You can use the long-lived token to make command line requests, for example using cURL. It can be useful when you need to counter-check bugs in the client library and to test new features or try to reproduce issues. In most cases, developers should use the client libraries as they are designed, as in this example.




Gunjan Sharma  Profile | Twitter

Gunjan is a Developer Programs Engineer working on Google Apps APIs. Before joining Google, he completed his degree in Computer Science & Engineering from Indian Institute of Technology, Roorkee.

Read more »

Tuesday, January 13, 2015

How to Install Windows from USB Disk



Install Windows from USB device



Today Im gonna share a very useful tip with you. In this post, you will learn - how to create a bootable USB disk (pen drive) for Windows/ Linux. And this is the easiest way to install Windows from USB disk. Earlier, I wrote about creating bootable Windows disk. 


If your PC doesnt have a DVD drive, or if your DVD drive is not functioning properly, you can use your pen drive to install Windows. And notebooks dont have DVD drive usually. To install Windows there, you must require a bootable pen drive. 



This post applies to:
  • Windows 7
  • Windows 8
  • Windows 8.1

I havent tested this technique for Windows XP. Maybe this will also work there. But Im not 100% sure about XP. 


In order to install Windows from USB Flash Drive, you need the following tools:
  • A USB Flash Drive/ Pen Drive (8 GB Recommended)
  • Windows ISO Image
  • Rufus - to create bootable USB disk

Step 1 - Get Windows ISO Image

Hopefully, all of you got an 8 GB pen drive. Now your task is to get an ISO image of your Windows. If you have a Windows Installation disk, you can prepare the ISO file using ISO Creator or by Infra Recorder. 


Step 2 - Create Bootable Disk

Now youve to create a bootable flash drive by Rufus. And then youre ready to install Windows from pen drive! Download Rufus from this link. Its just 616 KB. 

  1. Insert your pen drive. Back up the necessary files  of it (if any). And perform a quick format. 
  2. Run Rufus from your PC just by double click. 
  3. Device - Your pen drive, Partition Scheme - for BIOS and UEFI, File System - NTFS, Cluster Size - Default, Type your Windows Name in Volume > Choose Quick Format > Create a Bootable Disk using ISO Image > Hit on the CD icon and locate your ISO file > Select Extended Labels and Icon Files > Hit on the Start button to launch the operation.
  4. This may take a few minutes. Then you will get a confirmation message. Done! 

You can follow the image below:


Rufust - Creates bootable usb disk



Step 3 - Boot from USB Flash Drive

Restart your system. To access BIOS settings, you need to press F1 in case of Intel Mainboard. Gigabyte users will press Del key. And most other mainboards use F1 key to access to the BIOS utility. 

Now depending on your BIOS version, there could be different interface styles. But the basic option you need to find is - The Boot Priority or The Boot Order

To install the Windows from a USB disk, you need to select - Boot from USB Drive. Now Save and Exit from BIOS. Restart your PC. Now you will see the following message - 


Press any key to boot from USB...


Now press enter to start installing Windows from USB disk! If you face any problem, please leave a comment . . .




Wait a Minute!


When your PC copies files from the disk and restarts, the installation process may start again. If this happens to you, simply remove your pen drive and continue the installation process.




Stay with Marks PC Solution to get more interesting IT topics!


Read more »