public void Run(AdWordsUser user)
{
// Use a test account for which 2 factor authentication has been enabled.
string loginEmail = "[email protected]";
string password = "testaccount";
AdWordsAppConfig config = new AdWordsAppConfig();
config.Email = loginEmail;
config.Password = password;
AuthToken authToken = new AuthToken(config, "adwords");
try {
// Try to obtain an authToken.
string token = authToken.GetToken();
Console.WriteLine("Retrieved an authToken = {0} for user {1}.", token, loginEmail);
} catch (AuthTokenException ex) {
// Since the test account has 2 factor authentication enabled, this block
// of code will be executed.
if (ex.ErrorCode == AuthTokenErrorCode.BadAuthentication) {
if (ex.Info == "InvalidSecondFactor") {
Console.WriteLine("The user has enabled two factor authentication in this " +
"account. Have the user generate an application-specific password to make " +
"calls against the AdWords API. See " +
"http://adwordsapi.blogspot.com/2011/02/authentication-changes-with-2-step.html" +
" for more details.");
} else {
Console.WriteLine("Invalid credentials.");
}
} else {
throw new System.ApplicationException(String.Format("The server raised an {0} error.",
ex.ErrorCode));
}
}
}