Thursday, February 12, 2015

Getting OAuth 2.0 Access Token for Google AdWords API access

Accessing AdWords data via the Google AdWords API can be confusing and complicated, especially with the way Google Services API OAuth works.

In order to access AdWords via API, you'll (or your codes)  need to be authenticate via through OAuth 2.0. This guide is focusing on getting the OAuth Access token so that you can call the API from your codes.

To do this, we'll first need to create a credential to access the API. API credentials are manage with Google Developer Console.

  1. Create New Client ID using Google Developers Console. (See the steps here https://developers.google.com/adwords/api/docs/guides/authentication - Create a client identifier and client secret)
  2. During the step #7 choose Web application and enter 

    • "https://developers.google.com" in AUTHORIZED JAVASCRIPT ORIGINS 
    • "https://developers.google.com/oauthplayground" in AUTHORIZED REDIRECT URIS
    • Save and you will see the Client ID being created as below
Next, we're going to get a token for our API calls. This actually involves getting an Authorization code, a Refresh token and an Access token (this is the token we need for API calls).
  1. Head over to https://developers.google.com/oauthplayground, click on the gear icon on the top right corner and you'll see the following dialog.

  2. Check "Use your own OAuth credentials", and enter according the the screen shot below. The Adwords API is not in the selection, so you need to manually input "https://adwords.google.com/api/adwords" in the Select & authorize APIs input field.

    See the highlighted boxes in the screenshot. You'll also need the Cliend ID information that you previously generate.


  3. Click the "Authorize APIs" button and login with your AdWords Account when prompted (only if you're not already logged in)
  4. You will then be redirected back to the OAuth 2.0 Playground's Step 2. At this point, an Authorization code has been generated for the Client ID.

  5. Click on "Exchange authorization code for tokens" button, and the Access token will be generated for you. There will be a counter telling you when the Access token is going to be expired and you'll need to click the "Refresh access token" to renew it.
  6. That's it, that is how you get the OAuth 2.0 Access token for Google AdWords API.

Saturday, September 27, 2014

Sign-in automatically to Windows 8.1 without entering password

Every time Windows boot, I'm required to enter a password to logon to the Windows, while this is great security feature, though sometime I want the system just boot to desktop without any password.

Why? you ask, well just pure laziness I guess, and it's just a media server where I want to set this. I wanted to just press the power button of my PC, and the media server should just be ready. But because the media server service (Plex Media Server) required user to logon to Windows first before it starts itself on the system tray.

So here's the steps to set your Windows 8.1 PC to boot to Windows without any password.

1. Enter "control userpasswords2" in the Run menu (Win + R key), and press Enter.

2. Uncheck "Users must enter a user name and password to user this computer.",

enter your password when prompted.

Now try reboot the PC.

Tuesday, June 24, 2014

OneNote: We need the password to sync this notebook (Error code: 0xE4010643)

It happen to me once and it happen to me twice, and it happen again this morning.

When I saw this message, I knew no mater how many times I hit the "Sync All" it will never goes through (but I did it anyway).

I found these happen to me if I leave OneNote open, and put the computer to hibernate / sleep mode. Somehow when the computer awake from sleep, OneNote will failed to sync due to the credentials is out of sync. 

To avoid this I always close OneNote before putting the computer to sleep and often I simple shutdown the computer.

The fix to this is simply delete the cached credential used by OneNote to connect to server for synchronization, and re-login.


To do this, follow the following steps (Make sure you close OneNote before you proceed):
  1. Go to "Control Panel" > "User Accounts and Family Safety"
  2. Click "Credential Manager"
  3. Click "Manage Windows Credentials"
  4. Look for "MicrosoftOffice15_Data:live:cid=xxxxxxxxx"
  5. Expand the row and click "Remove" and click "Yes" when prompt to confirm.
  6. Don't start OneNote first, but instead, sign-out from Windows and sign-in again.
  7. Start OneNote and key in the credential when prompt. (sometime it doesn't prompt but it fixes the problem)
Update if removing item in step #4 doesn't work. Try removing the following
  • "MicrosoftAccount" - the credential you use to login to Windows
  • "OneDrive Cached Credential" 


Saturday, February 22, 2014

Express.JS quick-start guide on Windows

 

Express.JS is a fairly new but increasingly popular Node framework for building web application. Being a Node based application means you spin up a web application in just few steps. In this guide, I’m going to show a quick-start on just how to do this on Windows.

  1. Install node.js. See this tutorial if you don’t already have node.js on your Windows.
    • I’m using node v0.10.25, and express 3.4.8 on this guide.
  2. Create a directory for your new Express.JS app, run Command Prompt and cd into the directory. e.g. c:\users\<user name>\projects\fooApp
  3. Install express.js via npm ‘Node Package Manager’ that comes together with node.
    • In the Command Prompt, execute:

      npm install –g express

      image
    • Watch and wait for npm to complete fetching the required dependencies for express.js. It’s going to take a while.
  4. Once installation completed, you will be presented with a summary of what packages has been downloaded and it’s respective version.
    image
  5. Verify the Express.JS is installed and check it’s version with the command:

    express –-version

    Express will response with it’s version number.
    image
  6. Before continue with creating an Express app, have a look at what options is available for creating an Express app.

    express –-help

    image
    • If you do not specify any options, express will use it’s defaults that you see from this help screen
  7. Go ahead and create an express app. Execute:

    express fooApp

    For the sake of simplicity, I’m not going to specify any options.
    image
    • Express will shows a summary of what has been created, and notice that there are 2 short instructions and the end of the summary. So we going to follow exactly that.
  8. Before proceed with the instructions, lets have a look at the content of fooApp/package.json

    cd fooApp
    more package.json

    image
    • Like any other node.js application, the package.json defines the basic information for fooApp and it’s dependencies.
  9. Next we will install the related dependencies:
    npm install
    image
    • Once completed, npm will again shows a summary of what have been downloaded.
  10. Before proceed to run fooApp, take a quick look at these 3 files:
    • fooApp\app.js
    • fooApp\routes\index.js
    • fooApp\views\index.jade
    • app.js – This file define the runtime configuration for fooApp
      image

      routes\index.js & views\index.jade – This is the default route that will be executed when browse to fooApp.
      image
      This give us an idea of what to expect to see when browse to the fooApp, and more importantly the basic idea of the MVC pattern in an Express.JS application.
      The *.jade file is template using node template engine jade.
  11. Proceed to run fooApp, in the Command Prompt, execute:

    node app.js

    image
  12. Browse to http://localhost:3000
    image
    • It works, just like magic.

Thursday, February 13, 2014

Installing and upgrading node.js on Windows


Steps for installation:

  1. Go to http://nodejs.org/ and download the latest version of node.  I'll proceed with the Windows Installer (.msi) version.
    1. You can also go to http://nodejs.org/download/ to download installer for other platform.
  2. Run the node-XXXXXXXXXX.msi installer, and proceed to installation like a normal Windows application (basically just Next... , Agree, Next … Finish). I'd strongly suggest that you accepts all the default configurations and selections during the setup.


  3. Once installation completed, start a command prompt and type "node --version" and verify that it shows the version of node.


Steps for upgrade:

  1. I personally don't use any special tools to switch between version of nodes,  I prefer install if using the same Windows Installer. (If you uses all the default settings during setup, upgrading is simple repeating the installation steps to overwrite  the current version of node)
  2. If you want to use NVM (Node Version Manager) kind of tools that available to Linux users, you can use take a look at Nodist (https://github.com/marcelklehr/nodist). You can get Nodist via Chocolatey (http://chocolatey.org/).

Friday, January 3, 2014

Generating INSERT statement from SELECT using SQuirreL SQL

There are often time during development where you would want to test your application with various type of sample data, and you would want those data to be share with other team member as well.

The scenario that I ran into recently is we have some sample data that was enter to a system through a web interface, and for reports developments purposes we need those data to be shared among the team members, so we start to look into exporting those data out using SQL SELECT statements (with the correct WHERE clause) then converting them to equivalent INSERT statement; there are of cause several ways to do this, but I prefer the easy way, using SQuirreL SQL. The insert script can them be shared among the team members.

Following is the steps for completing this

  1. Install SQuirreL SQL
    • Make sure you have JRE7 installed on your machine
  2. Create connection to you database
    • Depending on your database type you need to use different drivers
    • Create the Alias to your database and enter the right connection strings (this can be tricky sometime)
  3. Start the connection session to you database
    • Select your alias and hit the Connect icon 
  4. Write you select statement and run it (CTRL+ENTER)
  5. Bring up the Tools dialog box (CTRL+T)
  6. Look for sql2ins and hit Enter
  7. Done. You will see INSERT statement will be generated right after your SELECT statements.
You can customize what columns you want on the generated INSERT statement by only specifying them in the SELECT statements, and don't forget you can also limit the records by specifying the where clause in your SELECT statements.

There you go, another magic trick.

Saturday, September 14, 2013

Default icons in Windows Phone SDK (use with ApplicationBarIconButton)

Windows Phone SDKs comes with icons that one can also use when developing an app, especially when creating an app bar (aka ApplicationBarIconButton),
These icons are located at

C:\Program Files (x86)\Microsoft SDKs\Windows Phone\vX.X\Icons\

There are different sets of icons, namely the dark icons set for use with a dark windows phone theme, and light icons set for use with light theme, and there is also vector based icons set.

Note: You should only use the icons under the dark folder, during runtime, Windows Phone will automatically put colors on the icons according to the theme selection

Always looks at the icons set and see if you can reuse any of the icons before creating yours, chances are high, icons you needs are already there.


Below is a snapshot of icons available in SDK v7.1 (32 icons)


icons for SDK v7.1

Add there are slightly more icons for SDK v8.0 (37 icons)



icons for SDK v8.0

Also, check out how to create an app bar using XAML on MSDN.