Hi There,
So, the process goes like this. Once the feed is created into Adwords, I
store the feed Id and Feed_item_Id into my database. And, I can see that a
particular feed has got generated and the feed_id and feed_item_id
generated is tored into my database. But I am not able to find the feed in
Adwords. Even if the feed is deleted from Adwords, I will still get that
feed_id with status as 'Removed' using the selector right?
Attached is my class for finding out the feeds in Adwords. Let me know if
there is any way to find this feed or anyne of you can find this feed for
me.
Thanks in Advance.
On Thursday, 7 March 2019 14:00:21 UTC+5:30, [email protected] wrote:
>
> I have a Feed_Id and I need to find out this id belongs to which
> Client_Customer_ID in Adwords using the Adwords API.
>
> Please let me know is there any selector using which we can achieve this.
>
> Regards,
> Shweta Padwekar
>
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/ee084e5f-c573-45af-9721-f68a0197d4c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
package adwords.axis.v201809.advancedoperations;
import static com.google.api.ads.common.lib.utils.Builder.DEFAULT_CONFIGURATION_FILENAME;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
import com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder;
import com.google.api.ads.adwords.axis.v201809.cm.AdCustomizerFeed;
import com.google.api.ads.adwords.axis.v201809.cm.AdCustomizerFeedPage;
import com.google.api.ads.adwords.axis.v201809.cm.AdCustomizerFeedServiceInterface;
import com.google.api.ads.adwords.axis.v201809.mcm.ManagedCustomer;
import com.google.api.ads.adwords.axis.v201809.mcm.ManagedCustomerLink;
import com.google.api.ads.adwords.axis.v201809.mcm.ManagedCustomerPage;
import com.google.api.ads.adwords.axis.v201809.mcm.ManagedCustomerServiceInterface;
import com.google.api.ads.adwords.lib.client.AdWordsSession;
import com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface;
import com.google.api.ads.adwords.lib.selectorfields.v201802.cm.ManagedCustomerField;
import com.google.api.ads.adwords.lib.selectorfields.v201809.cm.AdCustomizerFeedField;
import com.google.api.ads.common.lib.auth.OfflineCredentials;
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
import com.google.api.ads.common.lib.conf.ConfigurationLoadException;
import com.google.api.ads.common.lib.exception.OAuthException;
import com.google.api.ads.common.lib.exception.ValidationException;
import com.google.api.client.auth.oauth2.Credential;
import com.google.common.collect.Maps;
import com.google.common.collect.SortedSetMultimap;
import com.google.common.collect.TreeMultimap;
public class GetAllFeedsInClientCustomerID {
public static void main(String[] args) throws ValidationException, ConfigurationLoadException, RemoteException {
AdWordsSession session = null;
Credential oAuth2Credential = null;
try {
// Generate a refreshable OAuth2 credential.
oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.ADWORDS).fromFile().build()
.generateCredential();
// Construct an AdWordsSession.
session = new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
} catch (ConfigurationLoadException cle) {
System.err.printf("Failed to load configuration from the %s file. Exception: %s%n",
DEFAULT_CONFIGURATION_FILENAME, cle);
} catch (ValidationException ve) {
System.err.printf("Invalid configuration in the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME,
ve);
} catch (OAuthException oe) {
System.err.printf(
"Failed to create OAuth credentials. Check OAuth settings in the %s file. " + "Exception: %s%n",
DEFAULT_CONFIGURATION_FILENAME, oe);
}
AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();
List<Long> clientCustomerIds = getAccountHierarchy(adWordsServices, session);
System.out.println("All accounts present under root====" + clientCustomerIds);
for (Long clientCustomerId : clientCustomerIds) {
String clientCustId = clientCustomerId.toString();
session = new AdWordsSession.Builder().fromFile()
.withOAuth2Credential(oAuth2Credential).withClientCustomerId(clientCustId).build();
getAdCustomizerFeed(adWordsServices, session);
}
}
public static AdCustomizerFeed getAdCustomizerFeed(AdWordsServicesInterface adWordsServices,
AdWordsSession session) {
AdCustomizerFeed currentAdCustomizerFeed = null;
try {
AdCustomizerFeedServiceInterface adCustomizerFeedService = adWordsServices.get(session,
AdCustomizerFeedServiceInterface.class);
int pageSizeForFeed = 100;
int offsetForFeed = 0;
SelectorBuilder feedBuilder = new SelectorBuilder()
.fields(AdCustomizerFeedField.FeedId, AdCustomizerFeedField.FeedName,
AdCustomizerFeedField.FeedAttributes, AdCustomizerFeedField.FeedStatus)
.offset(offsetForFeed).limit(pageSizeForFeed);
AdCustomizerFeedPage adCustomizerFeedPage = null;
do {
adCustomizerFeedPage = adCustomizerFeedService.get(feedBuilder.build());
if (adCustomizerFeedPage.getEntries() != null) {
System.out.println("Client Customer Id :: "+ session.getClientCustomerId());
for (AdCustomizerFeed adCustomizerFeed : adCustomizerFeedPage.getEntries()) {
currentAdCustomizerFeed = adCustomizerFeed;
System.out.println(currentAdCustomizerFeed.getFeedId());
}
}
feedBuilder.increaseOffsetBy(pageSizeForFeed);
offsetForFeed += pageSizeForFeed;
} while (offsetForFeed < adCustomizerFeedPage.getTotalNumEntries());
} catch (RemoteException ex) {
System.out.println("Error while fetching existing feed from adwords for feed id in Database" + ex);
}
return currentAdCustomizerFeed;
}
public static List<Long> getAccountHierarchy(AdWordsServicesInterface adWordsServices, AdWordsSession session)
throws RemoteException {
int PAGE_SIZE = 500;
// Get the ServicedAccountService.
ManagedCustomerServiceInterface managedCustomerService = adWordsServices.get(session,
ManagedCustomerServiceInterface.class);
// Create selector builder.
int offset = 0;
SelectorBuilder selectorBuilder = new SelectorBuilder()
.fields(ManagedCustomerField.CustomerId, ManagedCustomerField.Name).offset(offset).limit(PAGE_SIZE);
// Get results.
ManagedCustomerPage page;
// Map from customerId to customer node.
Map<Long, ManagedCustomerTreeNode> customerIdToCustomerNode = Maps.newHashMap();
// Map from each parent customer ID to its set of linked child customer IDs.
SortedSetMultimap<Long, Long> parentIdToChildIds = TreeMultimap.create();
List<Long> clientCustomerIds = new ArrayList<Long>();
do {
page = managedCustomerService.get(selectorBuilder.build());
if (page.getEntries() != null) {
// Create account tree nodes for each customer.
for (ManagedCustomer customer : page.getEntries()) {
ManagedCustomerTreeNode node = new ManagedCustomerTreeNode();
node.account = customer;
customerIdToCustomerNode.put(customer.getCustomerId(), node);
}
// Update the map of parent customer ID to child customer IDs.
if (page.getLinks() != null) {
for (ManagedCustomerLink link : page.getLinks()) {
parentIdToChildIds.put(link.getManagerCustomerId(), link.getClientCustomerId());
if (!parentIdToChildIds.containsValue(link.getManagerCustomerId())) {
clientCustomerIds.add(link.getClientCustomerId());
}
}
}
}
offset += PAGE_SIZE;
selectorBuilder.increaseOffsetBy(PAGE_SIZE);
} while (offset < page.getTotalNumEntries());
System.out.println("clientCustomerIds");
System.out.println(clientCustomerIds);
return clientCustomerIds;
}
/**
* Example implementation of a node that would exist in an account tree.
*/
private static class ManagedCustomerTreeNode {
protected ManagedCustomerTreeNode parentNode;
protected ManagedCustomer account;
protected List<ManagedCustomerTreeNode> childAccounts = new ArrayList<ManagedCustomerTreeNode>();
/**
* Default constructor.
*/
public ManagedCustomerTreeNode() {
}
@Override
public String toString() {
return String.format("%s, %s, %s", account.getCustomerId(), account.getName());
}
}
}