Using a working DFA refresh token with AdWords

118 views
Skip to first unread message

jme...@gmail.com

unread,
Feb 2, 2015, 5:26:03 PM2/2/15
to adwor...@googlegroups.com
Hi,

I'm working on integrating a DFA refresh token with the AdWords service in a C# project. The WebConfig contains these key/values:

<add key="OAuth2ClientId" value="XXX.apps.googleusercontent.com" />

<add key="OAuth2ClientSecret" value="YYY" />

<add key="OAuth2RefreshToken" value="1/ZZZ" />


which are the same as used with DFA. When I attempt a request from AdWords, though, an exception is thrown:


'Google.Api.Ads.AdWords.Lib.AdWordsCredentialsExpiredException'


I tried a similar request using the AdWords test solution form GitHub and go the same results. My current DFA project continues to work fine with these credentials.


Also, I generated a new refresh token from the OAuth 2.0 Playground using the same account, but got an unauthorized account message when attempting to query the AdWords service. I only did this to test my code and would prefer to use just one token for both services.


I can't find a solution using the normal methods, so I can any help you throw my way would be really appreciated.


Thanks!

Michael Cloonan (AdWords API Team)

unread,
Feb 3, 2015, 3:01:37 PM2/3/15
to adwor...@googlegroups.com
Hello,

You must use a new refresh token with AdWords, as each refresh token allows for usage of a specific service as a specific account. This is a security measure; you shouldn't be able to use your DFA refresh token for AdWords because you only authenticated the usage of DFA.

Make sure to generate your refresh token when logged into the MCC account. If you're still having difficulties after doing that, please include the full error message you get when trying to make a request with your new refresh token.

Regards,
Mike, AdWords API Team

jme...@gmail.com

unread,
Feb 5, 2015, 2:20:50 PM2/5/15
to adwor...@googlegroups.com
Hi Michael,

Thanks for getting back to me with a reply. 

I generated a new refresh token from the OAuth Playground against this API:


I'm testing with the AdWords test project from GitHub and popped this in the app.config:

<add key="ClientCustomerId" value="111-222-3333"/>

<add key="OAuth2ClientId" value="444-xxx.apps.googleusercontent.com" />

<add key="OAuth2ClientSecret" value="yyy" />

<add key="OAuth2RefreshToken" value="1/zzz" />


I ran the TestGetCampaignsCSharpExample unit test and got this error:

Test Name: TestGetCampaignsCSharpExample
Test FullName: Google.Api.Ads.AdWords.Tests.v201409.BasicOperationsTest.TestGetCampaignsCSharpExample
Test Source: c:\googleads-dotnet-lib-master\tests\AdWords\v201409\BasicOperationsTest.cs : line 245
Test Outcome: Failed
Test Duration: 0:00:01.372

SetUp : Google.Api.Ads.Common.Lib.AdsOAuthException : Failed to refresh access token.
{
  "error" : "unauthorized_client"
}

Initially I tried this approach assuming that I the API would need a different token, but the error message suggested to me that I should use the same DFA token and was actually encouraged by the expiration message. I hoped that the client authorization was successful.

With another attempt and a new refresh token, I called the RefreshAccessTokenIfExpiring() method and passed the access token, which resulted in this exception:

'Google.Api.Ads.AdWords.Lib.AdWordsCredentialsExpiredException' 

When the method is not called, the API returns this message:

  "error" : "unauthorized_client"

My experience using OAuth with Google is limited to DFA. Please let me know what I'm missing with the above and I'll make the world right.

Regards

Michael Cloonan (AdWords API Team)

unread,
Feb 5, 2015, 2:51:06 PM2/5/15
to adwor...@googlegroups.com
Hello,

I believe this error message means that the refresh token you're using isn't actually associated with AdWords. There is an alternate way to fetch refresh tokens for AdWords compared to other Google products. Since it seems you are using the .NET library, I suggest checking out the OAuth2 examples folder for that library, which contains code examples for various OAuth2 use cases, including fetching the refresh token.

Regards,
Mike, AdWords API Team
Reply all
Reply to author
Forward
0 new messages