public void DoAuth2Authorization(AdWordsUser user, string authorizationCode) { try { AdsOAuthProviderForApplications oAuth2Provider = (user.OAuthProvider as AdsOAuthProviderForApplications); // Fetch the access and refresh tokens. oAuth2Provider.FetchAccessAndRefreshTokens(authorizationCode); } catch (Exception x) { throw new Exception(x.Message); } }
/// <summary> /// Does the OAuth2 authorization for installed applications. /// </summary> /// <param name="user">The DFP user.</param> private static void DoAuth2Authorization(DfpUser user) { // Since we are using a console application, set the callback url to null. user.Config.OAuth2RedirectUri = null; AdsOAuthProviderForApplications oAuth2Provider = (user.OAuthProvider as AdsOAuthProviderForApplications); // Get the authorization url. string authorizationUrl = oAuth2Provider.GetAuthorizationUrl(); Console.WriteLine("Open a fresh web browser and navigate to \n\n{0}\n\n. You will be " + "prompted to login and then authorize this application to make calls to the " + "DFP API. Once approved, you will be presented with an authorization code.", authorizationUrl); // Accept the OAuth2 authorization code from the user. Console.Write("Enter the authorization code :"); string authorizationCode = Console.ReadLine(); // Fetch the access and refresh tokens. oAuth2Provider.FetchAccessAndRefreshTokens(authorizationCode); }