コード例 #1
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            using (AdwordsUserListService userListService =
                       (AdwordsUserListService)user.GetService(AdWordsService.v201809
                                                               .AdwordsUserListService))
            {
                // Create a user list.
                CrmBasedUserList userList = new CrmBasedUserList()
                {
                    name = "Customer relationship management list #" +
                           ExampleUtilities.GetRandomString(),
                    description = "A list of customers that originated from email addresses",

                    // CRM - based user lists can use a membershipLifeSpan of 10000 to indicate
                    // unlimited; otherwise normal values apply.
                    membershipLifeSpan = 30L,
                    uploadKeyType      = CustomerMatchUploadKeyType.CONTACT_INFO
                };

                // Create operation.
                UserListOperation operation = new UserListOperation()
                {
                    operand   = userList,
                    @operator = Operator.ADD
                };

                try
                {
                    // Add user list.
                    UserListReturnValue result = userListService.mutate(new UserListOperation[]
                    {
                        operation
                    });

                    Console.WriteLine(
                        "Created new user list with name = '{0}' and id = " + "'{1}'.",
                        result.value[0].name, result.value[0].id);

                    // Get user list ID.
                    long userListId = result.value[0].id;

                    // Prepare the emails for upload.
                    List <Member> memberList = new List <Member>();

                    // Hash normalized email addresses based on SHA-256 hashing algorithm.
                    string[] emailHashes = new string[EMAILS.Length];
                    for (int i = 0; i < EMAILS.Length; i++)
                    {
                        Member member = new Member
                        {
                            hashedEmail = ToSha256String(digest, ToNormalizedEmail(EMAILS[i]))
                        };
                        memberList.Add(member);
                    }

                    ;

                    // Add a user by first and last name.
                    AddressInfo addressInfo = new AddressInfo
                    {
                        // First and last name must be normalized and hashed.
                        hashedFirstName = ToSha256String(digest, FIRST_NAME),
                        hashedLastName  = ToSha256String(digest, LAST_NAME),
                        // Country code and zip code are sent in plaintext.
                        zipCode     = ZIP_CODE,
                        countryCode = COUNTRY_CODE
                    };

                    Member memberByAddress = new Member
                    {
                        addressInfo = addressInfo
                    };
                    memberList.Add(memberByAddress);

                    // Create operation to add members to the user list based on email
                    // addresses.
                    MutateMembersOperation mutateMembersOperation = new MutateMembersOperation()
                    {
                        operand = new MutateMembersOperand()
                        {
                            userListId  = userListId,
                            membersList = memberList.ToArray()
                        },
                        @operator = Operator.ADD
                    };

                    // Add members to the user list based on email addresses.
                    MutateMembersReturnValue mutateMembersResult = userListService.mutateMembers(
                        new MutateMembersOperation[]
                    {
                        mutateMembersOperation
                    });

                    // Display results.
                    // Reminder: it may take several hours for the list to be populated
                    // with members.
                    foreach (UserList userListResult in mutateMembersResult.userLists)
                    {
                        Console.WriteLine(
                            "Email addresses were added to user list with " +
                            "name '{0}' and id '{1}'.", userListResult.name, userListResult.id);
                    }
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException(
                              "Failed to add user lists " +
                              "(a.k.a. audiences) and upload email addresses.", e);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            // Get the UserListService.
            AdwordsUserListService userListService =
                (AdwordsUserListService)user.GetService(
                    AdWordsService.v201710.AdwordsUserListService);

            // Create a user list.
            CrmBasedUserList userList = new CrmBasedUserList()
            {
                name = "Customer relationship management list #" +
                       ExampleUtilities.GetRandomString(),
                description = "A list of customers that originated from email " +
                              "addresses",

                // CRM Userlist has a maximum membership lifespan of 180 days. See
                // https://support.google.com/adwords/answer/6276125 for details.
                membershipLifeSpan = 180L,
            };

            // Create operation.
            UserListOperation operation = new UserListOperation()
            {
                operand   = userList,
                @operator = Operator.ADD
            };

            try {
                // Add user list.
                UserListReturnValue result = userListService.mutate(
                    new UserListOperation[] { operation });

                Console.WriteLine("Created new user list with name = '{0}' and id = " +
                                  "'{1}'.", result.value[0].name, result.value[0].id);

                // Get user list ID.
                long userListId = result.value[0].id;

                // Prepare the emails for upload.
                List <Member> memberList = new List <Member>();

                // Hash normalized email addresses based on SHA-256 hashing algorithm.
                String[] emailHashes = new String[EMAILS.Length];
                for (int i = 0; i < EMAILS.Length; i++)
                {
                    Member member = new Member();
                    member.hashedEmail = ToSha256String(digest, ToNormalizedEmail(EMAILS[i]));

                    // Adding address info is currently available on a whitelist-only basis. This
                    // code demonstrates how to do it, but if you are not on the whitelist, you
                    // will need to remove this block for the example to run.
                    AddressInfo addressInfo = new AddressInfo();
                    addressInfo.hashedFirstName = ToSha256String(digest, FIRST_NAME);
                    addressInfo.hashedLastName  = ToSha256String(digest, LAST_NAME);
                    addressInfo.zipCode         = ZIP_CODE;
                    addressInfo.countryCode     = COUNTRY_CODE;
                    member.addressInfo          = addressInfo;

                    memberList.Add(member);
                }
                ;

                // Create operation to add members to the user list based on email
                // addresses.
                MutateMembersOperation mutateMembersOperation =
                    new MutateMembersOperation()
                {
                    operand = new MutateMembersOperand()
                    {
                        userListId  = userListId,
                        membersList = memberList.ToArray()
                    },
                    @operator = Operator.ADD
                };

                // Add members to the user list based on email addresses.
                MutateMembersReturnValue mutateMembersResult =
                    userListService.mutateMembers(
                        new MutateMembersOperation[] { mutateMembersOperation });

                // Display results.
                // Reminder: it may take several hours for the list to be populated
                // with members.
                foreach (UserList userListResult in mutateMembersResult.userLists)
                {
                    Console.WriteLine("Email addresses were added to user list with " +
                                      "name '{0}' and id '{1}'.",
                                      userListResult.name, userListResult.id);
                }
                userListService.Close();
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to add user lists " +
                                                      "(a.k.a. audiences) and upload email addresses.", e);
            }
        }
コード例 #3
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            // Get the UserListService.
            AdwordsUserListService userListService =
                (AdwordsUserListService)user.GetService(
                    AdWordsService.v201607.AdwordsUserListService);

            // Create a user list.
            CrmBasedUserList userList = new CrmBasedUserList()
            {
                name = "Customer relationship management list #" +
                       ExampleUtilities.GetRandomString(),
                description = "A list of customers that originated from email " +
                              "addresses",

                // CRM Userlist has a maximum membership lifespan of 180 days. See
                // https://support.google.com/adwords/answer/6276125 for details.
                membershipLifeSpan = 180L,
            };

            // Create operation.
            UserListOperation operation = new UserListOperation()
            {
                operand   = userList,
                @operator = Operator.ADD
            };

            try {
                // Add user list.
                UserListReturnValue result = userListService.mutate(
                    new UserListOperation[] { operation });

                Console.WriteLine("Created new user list with name = '{0}' and id = " +
                                  "'{1}'.", result.value[0].name, result.value[0].id);

                // Get user list ID.
                long userListId = result.value[0].id;

                // Create operation to add members to the user list based on email
                // addresses.
                MutateMembersOperation mutateMembersOperation =
                    new MutateMembersOperation()
                {
                    operand = new MutateMembersOperand()
                    {
                        userListId = userListId,
                        dataType   = MutateMembersOperandDataType.EMAIL_SHA256
                    },
                    @operator = Operator.ADD
                };

                // Hash normalized email addresses based on SHA-256 hashing algorithm.
                String[] emailHashes = new String[EMAILS.Length];
                for (int i = 0; i < EMAILS.Length; i++)
                {
                    String normalizedEmail = ToNormalizedEmail(EMAILS[i]);
                    emailHashes[i] = ToSha256String(digest, normalizedEmail);
                }

                // Add email address hashes.
                mutateMembersOperation.operand.members = emailHashes;

                // Add members to the user list based on email addresses.
                MutateMembersReturnValue mutateMembersResult =
                    userListService.mutateMembers(
                        new MutateMembersOperation[] { mutateMembersOperation });

                // Display results.
                // Reminder: it may take several hours for the list to be populated
                // with members.
                foreach (UserList userListResult in mutateMembersResult.userLists)
                {
                    Console.WriteLine("Email addresses were added to user list with " +
                                      "name '{0}' and id '{1}'.",
                                      userListResult.name, userListResult.id);
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to add user lists " +
                                                      "(a.k.a. audiences) and upload email addresses.", e);
            }
        }
コード例 #4
0
        public void MergeFrom(UserList other)
        {
            if (other == null)
            {
                return;
            }
            if (other.ResourceName.Length != 0)
            {
                ResourceName = other.ResourceName;
            }
            if (other.id_ != null)
            {
                if (id_ == null || other.Id != 0L)
                {
                    Id = other.Id;
                }
            }
            if (other.readOnly_ != null)
            {
                if (readOnly_ == null || other.ReadOnly != false)
                {
                    ReadOnly = other.ReadOnly;
                }
            }
            if (other.name_ != null)
            {
                if (name_ == null || other.Name != "")
                {
                    Name = other.Name;
                }
            }
            if (other.description_ != null)
            {
                if (description_ == null || other.Description != "")
                {
                    Description = other.Description;
                }
            }
            if (other.MembershipStatus != 0)
            {
                MembershipStatus = other.MembershipStatus;
            }
            if (other.integrationCode_ != null)
            {
                if (integrationCode_ == null || other.IntegrationCode != "")
                {
                    IntegrationCode = other.IntegrationCode;
                }
            }
            if (other.membershipLifeSpan_ != null)
            {
                if (membershipLifeSpan_ == null || other.MembershipLifeSpan != 0L)
                {
                    MembershipLifeSpan = other.MembershipLifeSpan;
                }
            }
            if (other.sizeForDisplay_ != null)
            {
                if (sizeForDisplay_ == null || other.SizeForDisplay != 0L)
                {
                    SizeForDisplay = other.SizeForDisplay;
                }
            }
            if (other.SizeRangeForDisplay != 0)
            {
                SizeRangeForDisplay = other.SizeRangeForDisplay;
            }
            if (other.sizeForSearch_ != null)
            {
                if (sizeForSearch_ == null || other.SizeForSearch != 0L)
                {
                    SizeForSearch = other.SizeForSearch;
                }
            }
            if (other.SizeRangeForSearch != 0)
            {
                SizeRangeForSearch = other.SizeRangeForSearch;
            }
            if (other.Type != 0)
            {
                Type = other.Type;
            }
            if (other.ClosingReason != 0)
            {
                ClosingReason = other.ClosingReason;
            }
            if (other.AccessReason != 0)
            {
                AccessReason = other.AccessReason;
            }
            if (other.AccountUserListStatus != 0)
            {
                AccountUserListStatus = other.AccountUserListStatus;
            }
            if (other.eligibleForSearch_ != null)
            {
                if (eligibleForSearch_ == null || other.EligibleForSearch != false)
                {
                    EligibleForSearch = other.EligibleForSearch;
                }
            }
            if (other.eligibleForDisplay_ != null)
            {
                if (eligibleForDisplay_ == null || other.EligibleForDisplay != false)
                {
                    EligibleForDisplay = other.EligibleForDisplay;
                }
            }
            switch (other.UserListCase)
            {
            case UserListOneofCase.CrmBasedUserList:
                if (CrmBasedUserList == null)
                {
                    CrmBasedUserList = new global::Google.Ads.GoogleAds.V0.Common.CrmBasedUserListInfo();
                }
                CrmBasedUserList.MergeFrom(other.CrmBasedUserList);
                break;

            case UserListOneofCase.SimilarUserList:
                if (SimilarUserList == null)
                {
                    SimilarUserList = new global::Google.Ads.GoogleAds.V0.Common.SimilarUserListInfo();
                }
                SimilarUserList.MergeFrom(other.SimilarUserList);
                break;
            }

            _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }
コード例 #5
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ResourceName.Length != 0)
            {
                hash ^= ResourceName.GetHashCode();
            }
            if (id_ != null)
            {
                hash ^= Id.GetHashCode();
            }
            if (readOnly_ != null)
            {
                hash ^= ReadOnly.GetHashCode();
            }
            if (name_ != null)
            {
                hash ^= Name.GetHashCode();
            }
            if (description_ != null)
            {
                hash ^= Description.GetHashCode();
            }
            if (MembershipStatus != 0)
            {
                hash ^= MembershipStatus.GetHashCode();
            }
            if (integrationCode_ != null)
            {
                hash ^= IntegrationCode.GetHashCode();
            }
            if (membershipLifeSpan_ != null)
            {
                hash ^= MembershipLifeSpan.GetHashCode();
            }
            if (sizeForDisplay_ != null)
            {
                hash ^= SizeForDisplay.GetHashCode();
            }
            if (SizeRangeForDisplay != 0)
            {
                hash ^= SizeRangeForDisplay.GetHashCode();
            }
            if (sizeForSearch_ != null)
            {
                hash ^= SizeForSearch.GetHashCode();
            }
            if (SizeRangeForSearch != 0)
            {
                hash ^= SizeRangeForSearch.GetHashCode();
            }
            if (Type != 0)
            {
                hash ^= Type.GetHashCode();
            }
            if (ClosingReason != 0)
            {
                hash ^= ClosingReason.GetHashCode();
            }
            if (AccessReason != 0)
            {
                hash ^= AccessReason.GetHashCode();
            }
            if (AccountUserListStatus != 0)
            {
                hash ^= AccountUserListStatus.GetHashCode();
            }
            if (eligibleForSearch_ != null)
            {
                hash ^= EligibleForSearch.GetHashCode();
            }
            if (eligibleForDisplay_ != null)
            {
                hash ^= EligibleForDisplay.GetHashCode();
            }
            if (userListCase_ == UserListOneofCase.CrmBasedUserList)
            {
                hash ^= CrmBasedUserList.GetHashCode();
            }
            if (userListCase_ == UserListOneofCase.SimilarUserList)
            {
                hash ^= SimilarUserList.GetHashCode();
            }
            hash ^= (int)userListCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #6
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            // Get the UserListService.
              AdwordsUserListService userListService =
              (AdwordsUserListService) user.GetService(AdWordsService.v201509.AdwordsUserListService);

              // Create remarketing user list.
              CrmBasedUserList userList = new CrmBasedUserList() {
            name = "Customer relationship management list #" + ExampleUtilities.GetRandomString(),
            description = "A list of customers that originated from email addresses",

            // CRM Userlist has a maximum membership lifespan of 180 days. See
            // https://support.google.com/adwords/answer/6276125 for details.
            membershipLifeSpan = 180L,

            // This field is optional. It links to a service you created that allows members
            // of this list to remove themselves.
            optOutLink = "http://endpoint1.example.com/optout"
              };

              // Create operation.
              UserListOperation operation = new UserListOperation() {
            operand = userList,
            @operator = Operator.ADD
              };

              try {
            // Add user list.
            UserListReturnValue result = userListService.mutate(new UserListOperation[] { operation });

            Console.WriteLine("Created new user list with name = '{0}' and id = '{1}'.",
            result.value[0].name, result.value[0].id);

            // Get user list ID.
            long userListId = result.value[0].id;

            // Create operation to add members to the user list based on email
            // addresses.
            MutateMembersOperation mutateMembersOperation = new MutateMembersOperation() {
              operand = new MutateMembersOperand() {
            userListId = userListId,
            dataType = MutateMembersOperandDataType.EMAIL_SHA256
              },
              @operator = Operator.ADD
            };

            // Hash normalized email addresses based on SHA-256 hashing algorithm.
            String[] emailHashes = new String[EMAILS.Length];
            for (int i = 0; i < EMAILS.Length; i++) {
              String normalizedEmail = ToNormalizedEmail(EMAILS[i]);
              emailHashes[i] = ToSha256String(hashProvider, normalizedEmail);
            }

            // Add email address hashes.
            mutateMembersOperation.operand.members = emailHashes;

            // Add members to the user list based on email addresses.
            MutateMembersReturnValue mutateMembersResult =
            userListService.mutateMembers(new MutateMembersOperation[] { mutateMembersOperation });

            // Display results.
            // Reminder: it may take several hours for the list to be populated
            // with members.
            foreach (UserList userListResult in mutateMembersResult.userLists) {
              Console.WriteLine("Email addresses were added to user list with name '{0}' and " +
              "id '{1}'.", userListResult.name, userListResult.id);
            }
              } catch (Exception e) {
            throw new System.ApplicationException("Failed to add user lists (a.k.a. audiences) " +
            "and upload email addresses.", e);
              }
        }
コード例 #7
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(AdWordsUser user)
        {
            // Get the UserListService.
            AdwordsUserListService userListService =
                (AdwordsUserListService)user.GetService(AdWordsService.v201509.AdwordsUserListService);

            // Create remarketing user list.
            CrmBasedUserList userList = new CrmBasedUserList()
            {
                name        = "Customer relationship management list #" + ExampleUtilities.GetRandomString(),
                description = "A list of customers that originated from email addresses",

                // CRM Userlist has a maximum membership lifespan of 180 days. See
                // https://support.google.com/adwords/answer/6276125 for details.
                membershipLifeSpan = 180L,

                // You can optionally provide this field to conveniently link an
                // endpoint for opting-out members from this list. This would link to
                // a service you created that would appropriately remove members from
                // the relevant user list. Different user lists may use different
                // endpoints. Use this field to store the appropriate link.
                optOutLink = "http://endpoint1.example.com/optout"
            };

            // Create operation.
            UserListOperation operation = new UserListOperation()
            {
                operand   = userList,
                @operator = Operator.ADD
            };

            try {
                // Add user list.
                UserListReturnValue result = userListService.mutate(new UserListOperation[] { operation });

                Console.WriteLine("Created new user list with name = '{0}' and id = '{1}'.",
                                  result.value[0].name, result.value[0].id);

                // Get user list ID.
                long userListId = result.value[0].id;

                // Create operation to add members to the user list based on email
                // addresses.
                MutateMembersOperation mutateMembersOperation = new MutateMembersOperation()
                {
                    operand = new MutateMembersOperand()
                    {
                        userListId = userListId,
                        dataType   = MutateMembersOperandDataType.EMAIL_SHA256
                    },
                    @operator = Operator.ADD
                };

                // Hash normalized email addresses based on SHA-256 hashing algorithm.
                String[] emailHashes = new String[EMAILS.Length];
                for (int i = 0; i < EMAILS.Length; i++)
                {
                    String normalizedEmail = ToNormalizedEmail(EMAILS[i]);
                    emailHashes[i] = ToSha256String(hashProvider, normalizedEmail);
                }

                // Add email address hashes.
                mutateMembersOperation.operand.members = emailHashes;

                // Add members to the user list based on email addresses.
                MutateMembersReturnValue mutateMembersResult =
                    userListService.mutateMembers(new MutateMembersOperation[] { mutateMembersOperation });

                // Display results.
                // Reminder: it may take several hours for the list to be populated
                // with members.
                foreach (UserList userListResult in mutateMembersResult.userLists)
                {
                    Console.WriteLine("Email addresses were added to user list with name '{0}' and " +
                                      "id '{1}'.", userListResult.name, userListResult.id);
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to add user lists (a.k.a. audiences) " +
                                                      "and upload email addresses.", e);
            }
        }