First off. I'm really new to Google Ads API.
I'm trying to created a small C# console app to retrieve some basic ads
info (clicks, impressions..)
I have created a cloud app to get a client ID and secret. Enabled Google Ad
API.
I have the developer token from Google Ads API Center.
(It is still in Test Access level. I have applied for basic access, but
waiting on approval)
Then I needed to get a refresh token for my user. I used a tutorial program
to get that, so now (I think) I have all the GoogleAdsAPI info that I added
to app.config.
<GoogleAdsApi>
<add key="DeveloperToken" value="0ZkDzlCf7...removed..."/>
<add key = 'OAuth2Mode' value = 'APPLICATION' />
<add key = 'OAuth2ClientId' value =
'75347...removed...apps.googleusercontent.com' />
<add key = 'OAuth2ClientSecret' value = 'GOCSPX-o...removed...' />
<add key = 'OAuth2RefreshToken' value = '1//0chFAQh_a-BDWCg...removed...'
/>
<add key = 'LoginCustomerId' value = '9434...removed...' />
</GoogleAdsApi>
I then have this code I try to run:
GoogleAdsServiceClient googleAdsService =
client.GetService(Services.V14.GoogleAdsService);
string query =
@"SELECT
ad_group.id,
ad_group.name,
campaign.id,
campaign.name,
metrics.impressions,
metrics.clicks,
segments.device,
segments.day,
FROM ad_group
WHERE segments.date DURING LAST_7_DAYS
AND ad_group.status IN ('ENABLED','PAUSED')
ORDER BY metrics.impressions DESC
LIMIT 50";
try
{
// Issue a search request.
googleAdsService.SearchStream(customerId.ToString(), query,
delegate (SearchGoogleAdsStreamResponse resp)
{
// Display the results.
foreach (GoogleAdsRow criterionRow in resp.Results)
{
Console.WriteLine(
$"'{criterionRow.AdGroup.Name}' with ID " +
$"{criterionRow.AdGroup.Id} in campaign " +
$"'{criterionRow.Campaign.Name}' with ID " +
$"{criterionRow.Campaign.Id} had " +
$"{criterionRow.Metrics.Impressions.ToString()}
impressions, " +
$"{criterionRow.Metrics.Clicks} clicks " +
"during the last 7 days.");
}
}
);
}
catch (GoogleAdsException e)
{
Console.WriteLine("Failure:");
Console.WriteLine($"Message: {e.Message}");
Console.WriteLine($"Failure: {e.Failure}");
Console.WriteLine($"Request ID: {e.RequestId}");
throw;
}
But I get this error:
System.AggregateException: 'One or more errors occurred.
(Status(StatusCode="Internal", Detail="Error starting gRPC call.
TokenResponseException: Error:"invalid_request", Description:"Missing
required parameter: refresh_token", Uri:""",
DebugException="Google.Apis.Auth.OAuth2.Responses.TokenResponseException:
Error:"invalid_request", Description:"Missing required parameter:
refresh_token", Uri:""
at
Google.Apis.Auth.OAuth2.Responses.TokenResponse.FromHttpResponseAsync(HttpResponseMessage
response, IClock clock, ILogger logger)
at
Google.Apis.Auth.OAuth2.Requests.TokenRequestExtenstions.ExecuteAsync(TokenRequest
request, HttpClient httpClient, String tokenServerUrl, CancellationToken
taskCancellationToken, IClock clock, ILogger logger)
at
Google.Apis.Auth.OAuth2.Flows.AuthorizationCodeFlow.FetchTokenAsync(String
userId, TokenRequest request, CancellationToken taskCancellationToken)
at
Google.Apis.Auth.OAuth2.Flows.AuthorizationCodeFlow.FetchTokenAsync(String
userId, TokenRequest request, CancellationToken taskCancellationToken)
at
Google.Apis.Auth.OAuth2.Flows.AuthorizationCodeFlow.RefreshTokenAsync(String
userId, String refreshToken, CancellationToken taskCancellationToken)
at
Google.Apis.Auth.OAuth2.UserCredential.RefreshTokenAsync(CancellationToken
taskCancellationToken)
at Google.Apis.Auth.OAuth2.TokenRefreshManager.RefreshTokenAsync()
at
Google.Apis.Auth.OAuth2.UserCredential.GetAccessTokenWithHeadersForRequestAsync(String
authUri, CancellationToken cancellationToken)
at
Google.Apis.Auth.OAuth2.TokenRefreshManager.<GetAccessTokenForRequestAsync>g__LogException|10_0(Task
task)
at
Grpc.Auth.GoogleAuthInterceptors.<>c__DisplayClass3_0.<<FromCredential>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at
Grpc.Net.Client.Internal.GrpcProtocolHelpers.ReadCredentialMetadata(DefaultCallCredentialsConfigurator
configurator, GrpcChannel channel, HttpRequestMessage message, IMethod
method, CallCredentials credentials)
at
Grpc.Net.Client.Internal.GrpcCall`2.ReadCredentials(HttpRequestMessage
request)
at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage
request, Nullable`1 timeout)"))'
It says the refresh token isn't there... But it is in my config file...
What I'm I missing/doing wrong??
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
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
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/f15a4b90-00a7-4e2a-8f19-9df67d504106n%40googlegroups.com.