Hello, Once you issue the line of code, your *oAuth* (OAuth2ProviderForApplications) instance will be populated with a refresh token.
oAuth.FetchAccessAndRefreshTokens(Request.Params["code"]); You can try accessing the refresh token and setting it in the *config* (AdWordsAppConfig) before making the call to CustomerService. String refreshToken = oAuth.RefreshToken; config.OAuth2RefreshToken = refreshToken; Double-check to make sure that you have a refresh token at that point. If not, then there may be an issue with your credentials before you even fetch the refresh token. Cheers, Nadine, AdWords API Team On Thursday, April 2, 2015 at 6:13:57 AM UTC-4, Marcin Gdak wrote: > > Thank for your replies :) > > I have another problem. I am working with the option 2. > > My code: > AdWordsUser user = new AdWordsUser(); > CustomerService customerservice = > (CustomerService)user.GetService(AdWordsService.v201502.CustomerService); > long customerId = customerservice.get().customerId; -> Here I am > getting the error, that in webconfig I must have refreshToken. > > My Authentication code: > > Site from Redirect URIs > > protected void Page_Load(object sender, EventArgs e) > { > AdWordsAppConfig config = new AdWordsAppConfig(); > if (config.OAuth2Mode == OAuth2Flow.APPLICATION && > string.IsNullOrEmpty(config.OAuth2RefreshToken)) > { > DoAuth2Configuration(config); > } > if (!string.IsNullOrEmpty(config.OAuth2RefreshToken)) > { > Response.Redirect("/Pages/Default.aspx"); > } > } > private void DoAuth2Configuration(AdWordsAppConfig config) > { > config.OAuth2RedirectUri = > Request.Url.GetLeftPart(UriPartial.Path); > OAuth2ProviderForApplications oAuth = > new OAuth2ProviderForApplications(config); > if (Request.Params["state"] == null) > { > oAuth.State = "callback"; > Response.Redirect(oAuth.GetAuthorizationUrl()); > } > else if (Request.Params["state"] == "callback") > {oAuth.FetchAccessAndRefreshTokens(Request.Params["code"]); > Session["OAuthProvider"] = oAuth; > // Redirect the user to the main page. > Response.Redirect("Pages/Default.aspx"); > } > > I would like to write in webconfig refreshtoken after the authorization, > but oAuth.RefreshToken is null. How can i get RefreshToken from my > Authorization code? I don't understand it :( > -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ Also find us on our blog and Google+: https://googleadsdeveloper.blogspot.com/ https://plus.google.com/+GoogleAdsDevelopers/posts =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ You received this message because you are subscribed to the Google Groups "AdWords API Forum" group. To post to this group, send email to adwords-api@googlegroups.com To unsubscribe from this group, send email to adwords-api+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/adwords-api?hl=en --- You received this message because you are subscribed to the Google Groups "AdWords API Forum" group. To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/adwords-api. To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/81c58478-76b6-4664-995f-9ad2f7d040bc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.