Anyone familiar with Yammer will know that many of the APIs are a bit lacking. Also, all API connections will need an oAuth token that has access to the data in question. So what do you do if you have a console application that needs to use Yammer Data Export API and drop the into a database or more to the point, how do you get the oAuth token? I am not going to post the specifics on how to get the data and extract it but I will post some code on how to get the oAuth token.
To start there is some information you will need from Yammer which is only obtained after creating a Yammer app (https://developer.yammer.com/v1.0/docs/app-registration). Your redirect URL for the included code needs to be http://localhost:80/Temporary_Listen_Addresses/ (if you get an error relating to access denied the port may be being used or it could be an issue with your privileges on the device). *NOTE you do not need to publish your app for this functionality to work, so you can create the app then never finalize it. Yammer's documentation https://developer.yammer.com/v1.0/docs/authentication-1 does not include the specifics on how to implement this on a console application and only includes the basic information.
The included code makse the assumptions that you will have the following app seetings in your App.config: "ClientID", "RedirectURL", "ClientSecret", and "oAuthToken" with all of these fields populated, with the exception of the "oAuthToken" field, from the information in your Yammer app settings.
I have included the complete class to perform the login here and to implement it you just need to call the constructor.
- string token = yammerLogin.oAuthToken;
The oAuthToken will be stored in the App.config and it will only re-auth if the token has failed to login.
I hope this will help save a few hours of work for a few people out there.