Skip to content

Commit

Permalink
Changes for Google Ads API v0_6. (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoryLiseno authored Dec 3, 2018
1 parent b4fb22c commit 812629a
Show file tree
Hide file tree
Showing 321 changed files with 78,390 additions and 1,737 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.7.0
=====

- Added support for Google Ads API v0.6.0. See release notes:
https://developers.google.com/google-ads/api/docs/release-notes#060_2018-11-29

0.6.0
=====

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ public static void Main(string[] args)
$"<add key = 'OAuth2RefreshToken' value = " +
$"'{credential.Token.RefreshToken}' />\n");

Console.WriteLine("/n" +
"<!-- Required for manager accounts only: Specify the login customer -->\n" +
"<!-- ID used to authenticate API calls. This will be the customer ID -->\n" +
"<!-- of the authenticated manager account. It should be set without -->\n" +
"<!-- dashes, for example: 1234567890 instead of 123-456-7890. You can -->\n" +
"<!-- also specify this later in code if your application uses -->\n" +
"<!-- multiple manager account OAuth pairs. -->\n" +
"<add key = 'LoginCustomerId' value = INSERT_LOGIN_CUSTOMER_ID_HERE />/n/n");

Console.WriteLine("Press <Enter> to continue...");
Console.ReadLine();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<ProjectReference Condition="Exists('..\..\..\src\Google.Ads.GoogleAds.csproj')" Include="..\..\..\src\Google.Ads.GoogleAds.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Google.Ads.GoogleAds, Version=0.6.0.0, Culture=neutral, PublicKeyToken=52807268f2b614dc, processorArchitecture=MSIL">
<Reference Include="Google.Ads.GoogleAds, Version=0.7.0.0, Culture=neutral, PublicKeyToken=52807268f2b614dc, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Google.Ads.GoogleAds.0.6.0\lib\net452\Google.Ads.GoogleAds.dll</HintPath>
</Reference>
<Reference Include="Google.Api.CommonProtos, Version=1.3.0.0, Culture=neutral, PublicKeyToken=3ec5ea7f18953e47, processorArchitecture=MSIL">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@
<add key="OAuth2PrnEmail" value="INSERT_OAUTH2_USER_EMAIL_HERE" />
<add key="OAuth2SecretsJsonPath" value="INSERT_OAUTH2_SECRETS_JSON_FILE_PATH_HERE" />
-->

<!-- Required for manager accounts only: Specify the login customer ID used to authenticate
API calls. This will be the customer ID of the authenticated manager account. It should
be set without dashes, for example: 1234567890 instead of 123-456-7890. You can also
specify this later in code if your application uses multiple manager account OAuth pairs.
-->
<!--
<add key = 'LoginCustomerId' value = 'INSERT_LOGIN_CUSTOMER_ID_HERE' />/n/n
-->
</GoogleAdsApi>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Google.Ads.GoogleAds" version="0.6.0" targetFramework="net452" />
<package id="Google.Ads.GoogleAds" version="0.7.0" targetFramework="net452" />
<package id="Google.Api.CommonProtos" version="1.3.0" targetFramework="net452" />
<package id="Google.Api.Gax" version="2.5.0" targetFramework="net452" />
<package id="Google.Api.Gax.Grpc" version="2.5.0" targetFramework="net452" />
Expand Down
8 changes: 6 additions & 2 deletions examples/Services/BasicOperations/GetCampaigns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ public void Run(GoogleAdsClient client, long customerId)
SearchGoogleAdsRequest request = new SearchGoogleAdsRequest()
{
PageSize = PAGE_SIZE,
Query = "SELECT campaign.id, campaign.network_settings.target_content_network " +
"FROM campaign ORDER BY campaign.id",
Query = @"SELECT
campaign.id,
campaign.name,
campaign.network_settings.target_content_network
FROM campaign
ORDER BY campaign.id",
CustomerId = customerId.ToString()
};

Expand Down
2 changes: 1 addition & 1 deletion examples/Services/Google.Ads.GoogleAds.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Ads.GoogleAds" Version="0.6.0" />
<PackageReference Include="Google.Ads.GoogleAds" Version="0.7.0" />
<PackageReference Include="Mono.Options" Version="5.3.0.1" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion examples/Services/Recommendations/ApplyRecommendation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ public void Run(GoogleAdsClient client, long customerId, long recommendationId)
// }
};

bool partialFailure = false;

try
{
ApplyRecommendationResponse response = service.ApplyRecommendation(
customerId.ToString(), new ApplyRecommendationOperation[] { operation });
customerId.ToString(), partialFailure, new ApplyRecommendationOperation[] {
operation
});
Console.WriteLine($"Applied {0} recommendation(s):", response.Results.Count);
foreach (ApplyRecommendationResult result in response.Results)
{
Expand Down
43 changes: 42 additions & 1 deletion examples/Services/Targeting/AddCampaignTargetingCriteria.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System;

using static Google.Ads.GoogleAds.V0.Enums.KeywordMatchTypeEnum.Types;
using static Google.Ads.GoogleAds.V0.Enums.ProximityRadiusUnitsEnum.Types;

namespace Google.Ads.GoogleAds.Examples.V0
{
Expand Down Expand Up @@ -93,6 +94,9 @@ public void Run(GoogleAdsClient client, long customerId, long campaignId,
CampaignCriterion locationCriterion = buildLocationCriterion(locationId,
campaignResourceName);

// Add a proximity criterion
CampaignCriterion proximityCriterion = buildProximityCriterion(campaignResourceName);

// Create the operations.
CampaignCriterionOperation negativeCriterionOperation =
new CampaignCriterionOperation()
Expand All @@ -106,9 +110,16 @@ public void Run(GoogleAdsClient client, long customerId, long campaignId,
Create = locationCriterion
};

CampaignCriterionOperation proximityCriterionOperation =
new CampaignCriterionOperation()
{
Create = proximityCriterion
};

CampaignCriterionOperation[] operations = new CampaignCriterionOperation[] {
negativeCriterionOperation,
locationCriterionOperation
locationCriterionOperation,
proximityCriterionOperation
};

try
Expand Down Expand Up @@ -178,5 +189,35 @@ private CampaignCriterion buildLocationCriterion(long locationId,
}
};
}

/// <summary>
/// Creates a proximity Criterion.
/// </summary>
/// <param name="campaignResourceName">the campaign where the proximity will be added.
/// </param>
/// <returns>a campaign criterion object with the specified locationId and resource name.
/// </returns>
private CampaignCriterion buildProximityCriterion(string campaignResourceName)
{
ProximityInfo proximity = new ProximityInfo()
{
Address = new AddressInfo()
{
StreetAddress = "38 avenue de l'Opéra",
CityName = "Paris",
PostalCode = "75002",
CountryCode = "FR"
},
Radius = 10d,
// Default is kilometers.
RadiusUnits = ProximityRadiusUnits.Miles
};

return new CampaignCriterion()
{
Campaign = campaignResourceName,
Proximity = proximity
};
}
}
}
11 changes: 10 additions & 1 deletion examples/Services/Targeting/GetGeoTargetConstantsByName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,20 @@ public void Run(GoogleAdsClient client)
GeoTargetConstantServiceClient geoService =
client.GetService(Services.V0.GeoTargetConstantService);

// Locale is using ISO 639-1 format. If an invalid locale is given,
// 'en' is used by default.
string locale = "en";

// A list of country codes can be referenced here:
// https://developers.google.com/adwords/api/docs/appendix/geotargeting
string countryCode = "FR";

String[] locations = { "Paris", "Quebec", "Spain", "Deutschland" };

SuggestGeoTargetConstantsRequest request = new SuggestGeoTargetConstantsRequest()
{
Locale = "en",
Locale = locale,
CountryCode = countryCode,
LocationNames = new SuggestGeoTargetConstantsRequest.Types.LocationNames()
};

Expand Down
9 changes: 9 additions & 0 deletions src/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@
<add key="OAuth2PrnEmail" value="INSERT_OAUTH2_USER_EMAIL_HERE" />
<add key="OAuth2SecretsJsonPath" value="INSERT_OAUTH2_SECRETS_JSON_FILE_PATH_HERE" />
-->

<!-- Required for manager accounts only: Specify the login customer ID used to authenticate
API calls. This will be the customer ID of the authenticated manager account. It should
be set without dashes, for example: 1234567890 instead of 123-456-7890. You can also
specify this later in code if your application uses multiple manager account OAuth pairs.
-->
<!--
<add key = 'LoginCustomerId' value = 'INSERT_LOGIN_CUSTOMER_ID_HERE' />/n/n
-->
</GoogleAdsApi>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
Expand Down
23 changes: 22 additions & 1 deletion src/Config/GoogleAdsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,20 @@ public class GoogleAdsConfig : ConfigBase
/// </summary>
/// <remarks>This setting is used only for testing purposes.</remarks>
private readonly ConfigSetting<string> serverUrl = new ConfigSetting<string>(
"GoogleAds.Server", GOOGLE_ADS_API_SERVER_URL);
"ServerUrl", GOOGLE_ADS_API_SERVER_URL);

/// <summary>
/// The developer token.
/// </summary>
private readonly ConfigSetting<string> developerToken = new ConfigSetting<string>(
"DeveloperToken", "");

/// <summary>
/// The Login Customer ID.
/// </summary>
private readonly ConfigSetting<string> loginCustomerId = new ConfigSetting<string>(
"LoginCustomerId", "");

/// <summary>
/// Gets or sets the timeout for individual API calls.
/// </summary>
Expand Down Expand Up @@ -197,6 +203,21 @@ public string DeveloperToken
set => SetPropertyAndNotify(developerToken, value);
}

/// <summary>
/// Gets or sets the login customer id.
/// </summary>
/// <remarks>
/// Required for manager accounts only. When authenticating as a Google Ads
/// manager account, specifies the customer ID of the authenticating manager account.
/// If your OAuth credentials are for a user with access to multiple manager accounts you
/// must create a separate GoogleAdsClient instance for each manager account.
/// </remarks>
public string LoginCustomerId
{
get => loginCustomerId.Value;
set => SetPropertyAndNotify(loginCustomerId, value);
}

/// <summary>
/// Gets or sets the OAuth2 server URL.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Google.Ads.GoogleAds.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Title>Google Ads API Dotnet Client Library</Title>
<PackageId>Google.Ads.GoogleAds</PackageId>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<Description>This library provides you with functionality to access the Google Ads API.</Description>
<PackageReleaseNotes>https://github.com/googleads/google-ads-dotnet/blob/master/ChangeLog</PackageReleaseNotes>
<PackageTags>GoogleAds Google</PackageTags>
Expand All @@ -30,8 +30,8 @@
<IncludeSource>true</IncludeSource>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyVersion>0.6.0.0</AssemblyVersion>
<FileVersion>0.6.0.0</FileVersion>
<AssemblyVersion>0.7.0.0</AssemblyVersion>
<FileVersion>0.7.0.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<Content Include="app.config.transform" PackagePath="content" />
Expand Down
6 changes: 6 additions & 0 deletions src/Lib/GoogleAdsServiceClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ private GoogleAdsServiceContext CreateServiceContext(GoogleAdsConfig config)
GoogleAdsResponseMetadata responseMetadata = new GoogleAdsResponseMetadata(metadata);
serviceContext.OnResponseMetadataReceived(responseMetadata);
});

if (!string.IsNullOrEmpty(config.LoginCustomerId))
{
callSettings.WithHeader("login-customer-id", config.LoginCustomerId);
}

serviceContext.CallSettings = callSettings;
return serviceContext;
}
Expand Down
Loading

0 comments on commit 812629a

Please sign in to comment.