Easily retrieve Yammer Access token for demo purposes

In this blog post, I’ll show you how to easily retrieve a Yammer access token to use for demo purposes. Please note, the method showed here is purely meant as that; for demo purposes. In an actual production scenario, you can follow the steps found at https://developer.yammer.com/v1.0/docs/authentication-1 . If you’re just quickly looking for the access token, to demo the cool stuff you can do with the Yammer API, then this blog post is for you.

Create a new Yammer App
In order to do any demo’ing at all, you’ll first need to register a new app. To do so, first go to https://developer.yammer.com/v1.0/docs/yammer-partners and click on ‘Register an App’. You’ll be redirected to a new page that shows all the apps you currently have. On the left side click ‘Register new app’. The following screen should appear:

Yammer1

You can fill in any values you like, but for the Redirection URL please fill in https://localhost. This will be what allows us to easily retrieve our access token.

After your app has been created, it is important to note that if you want to do any Javascript requests with your app, you should also white list the domain your app is using in the settings. To do so, after the app has been created, click on ‘Basic info’ on the left side of the screen:

Yammer2

Underneath the heading ‘Installation Information’ you have a field called ‘Javascript origins’ which is the field where you want to add your custom domain that you are using for those javascript calls. If you do not specify your domain here, your app will get blocked from performing any javascript calls. This is done for security reasons, so not everyone can ‘fake’ being your app from any domain out there.

Retrieving the Access Token for a particular demo user
Now that we have our app registered at Yammer, we can actually retrieve the access token. This process is as simple as performing a GET request in the browser. We use the following structure:

https://www.yammer.com/dialog/oauth?client_id=%5B:client_id%5D&redirect_uri=%5B:redirect_uri%5D

For the client ID, specify your app’s client ID that you just created. You can find that by clicking on the name of your app in the left menu on yammer. For the redirect URL we can use the value specified as ‘Expected redirect’. Your final URL would be something like

https://www.yammer.com/dialog/oauth?client_id=7SDwM0l5KG0EHm8Ejp2HLx&redirect_uri=https://localhost.

If you’ve done everything properly, Yammer should now ask for your user credentials. The access token given will be based off of these credentials. Fill in your credentials and you’ll be redirected to your Expected Redirect URL. Although this will not actually work, since your localhost is not configured to do anything with this information yet. You will however be able to retrieve the code that is required for the next and final step. In the address bar, take note of the code given. For the last step in this process, create a URL as structured below:

https://www.yammer.com/oauth2/access_token.json?client_id=%5BclientId%5D&client_secret=%5BclientSecret%5D&code=

You already know where to find the values for clientId and clientSecret, and you’ve just found the code. Now go to this address in the browser and you’ll be able to download a json object. This object contains the actual access token. You can find it by opening the json file in your prefered development program and looking for the keyword ‘Token’. The value after the : will be the value you want. You can then use that Bearer access token in your custom application to perform Yammer API calls. And since the access token actually does not expire for quite some time, you’ll good to go! Happy coding!