Skip to content

Commit

Permalink
Merge pull request #561 from googleads/restructure-aiv-example
Browse files Browse the repository at this point in the history
Restructure the VerifyAdvertiserIdentity example to use the ProgramStatus enum to drive the flow instead of the presence or absence of the actionUrl
  • Loading branch information
Raibaz authored Apr 5, 2024
2 parents 14b224e + 99b347f commit 77b46c1
Showing 1 changed file with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
using Google.Ads.GoogleAds.V16.Errors;
using Google.Ads.GoogleAds.V16.Services;
using static Google.Ads.GoogleAds.V16.Enums.IdentityVerificationProgramEnum.Types;
using static Google.Ads.GoogleAds.V16.Enums.IdentityVerificationProgramStatusEnum.Types;
using System;
using Google.Ads.GoogleAds.Config;
using Google.Ads.GoogleAds.Extensions.Config;

namespace Google.Ads.GoogleAds.Examples.V16
{
Expand Down Expand Up @@ -73,37 +76,47 @@ public void Run(GoogleAdsClient client, long customerId)
IdentityVerification identityVerification =
GetIdentityVerification(client, customerId);

if (identityVerification != null)
if (identityVerification == null)
{
if (identityVerification.VerificationProgress.ActionUrl == null)
{
StartIdentityVerification(client, customerId);

// Call GetIdentityVerification again to retrieve the verification progress
// after starting an identity verification session.
GetIdentityVerification(client, customerId);

} else {
// If there is an identity verification session in progress, there is no need
// to start another one by calling StartIdentityVerification.
Console.WriteLine("There is an advertiser identity verification session in " +
"progress.\n" +
"The URL for the verification process is: " +
identityVerification.VerificationProgress.ActionUrl +
" and it will expire at " +
identityVerification.VerificationProgress.InvitationLinkExpirationTime);
}
}
else
{
// If GetIdentityVerification returned an empty response, the account is not
// enrolled in mandatory identity verification.
Console.WriteLine($"Account {customerId} is not required to perform advertiser " +
"identity verification.\n" +
"See https://support.google.com/adspolicy/answer/9703665 for details on how " +
"and when an account is required to undergo the advertiser identity " +
"verification program.");
return;
}

switch(identityVerification.VerificationProgress.ProgramStatus)
{
case IdentityVerificationProgramStatus.Unspecified:
// Starts an identity verification session.
StartIdentityVerification(client, customerId);
// Calls GetIdentityVerification again to retrieve the verification progress
// after starting an identity verification session.
GetIdentityVerification(client, customerId);
break;
case IdentityVerificationProgramStatus.PendingUserAction:
// If there is an identity verification session in progress, there is no
// need to start another one by calling StartIdentityVerification.
Console.WriteLine("There is an advertiser identity verification session " +
"in progress.\n" +
"The URL for the verification process is: " +
identityVerification.VerificationProgress.ActionUrl +
" and it will expire at " +
identityVerification.VerificationProgress.InvitationLinkExpirationTime);
break;
case IdentityVerificationProgramStatus.PendingReview:
Console.WriteLine("The verification is under review.");
break;
case IdentityVerificationProgramStatus.Success:
Console.WriteLine("The verification completed successfully.");
break;
default:
Console.WriteLine("The verification has an unknown state.");
break;
}
}

Expand Down

0 comments on commit 77b46c1

Please sign in to comment.