Posts tagged with google-api

I am new to Google AdWords API.

Right now I am downloading the AD_PERFORMANCE_REPORT and I want to segment it by day, but I cant find the right example in their documentation

My code looks like this:

 def get_data(customer_id):     df = None     for item in customer_id:         report_query = (adwords.ReportQueryBuilder()                         .Select('AdGroupId', 'AdGroupName', 'AbsoluteTopImpressionPercentage', 'Impressions', 'Conversions')                         .From('AD_PERFORMANCE_REPORT')                         .During('LAST_7_DAYS')                         .Build())         # You can provide a file object to write the output to. For this         # demonstration we use sys.stdout to write the report to the screen.         report_downloader.DownloadReportWithAwql(             report_query,             'CSV',             output,             client_customer_id=item,  # denotes which adw account to pull from             skip_report_header=True,             skip_column_header=False,             skip_report_summary=True,             include_zero_impressions=False)         output.seek(0)         df = pd.read_csv(output)         if df is None:             df = pd.DataFrame(output)         else:             df = df.append(pd.DataFrame(output))     return df 

Thank you for your suggestions.

I already have a campaign budget which i want to update using google AdWords API.

   BudgetServiceInterface budgetService =         adWordsServices.get(session, BudgetServiceInterface.class);     // Create a budget, which can be shared by multiple campaigns.     Budget sharedBudget = new Budget();     sharedBudget.setName("Interplanetary Cruise #" + System.currentTimeMillis());     Money budgetAmount = new Money();     budgetAmount.setMicroAmount(50_000_000L);     sharedBudget.setAmount(budgetAmount);     sharedBudget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);     BudgetOperation budgetOperation = new BudgetOperation();     budgetOperation.setOperand(sharedBudget);     budgetOperation.setOperator(Operator.ADD);     // Add the budget     Long budgetId =         budgetService.mutate(new BudgetOperation[] {budgetOperation}).getValue(0).getBudgetId();     // Get the CampaignService.     CampaignServiceInterface campaignService =         adWordsServices.get(session, CampaignServiceInterface.class); 

Assiging budgetId to campaign

    Budget budget = new Budget();     budget.setBudgetId(budgetId);     campaign.setBudget(budget); 

This will unassign existing campaign budget and assign new campaign budget to the campaign ( campaign budget is not removed and it still exist in google ads) but I want to update the budget name and budget amount of existing campaign budget rather than assigning new campaign budget.

I am new to Google AdWords API. There is no mention of Keyword in UpdateKeyword class of Google AdWords API, It is only used to update MaxCPC using criterionId. Normally Google AdWords API's are pretty simple, but I am not getting how to update keyword properties. How do I update keyword, KeywordmMatchType, and maxCPC?

  public static void runExample(       AdWordsServicesInterface adWordsServices,       AdWordsSession session,       Long adGroupId,       Long keywordId)       throws RemoteException {     // Get the AdGroupCriterionService.     AdGroupCriterionServiceInterface adGroupCriterionService =         adWordsServices.get(session, AdGroupCriterionServiceInterface.class);     // Create ad group criterion with updated bid.     Criterion criterion = new Criterion();     criterion.setId(keywordId);     BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();     biddableAdGroupCriterion.setAdGroupId(adGroupId);     biddableAdGroupCriterion.setCriterion(criterion);     // Create bids.     BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();     CpcBid bid = new CpcBid();     bid.setBid(new Money(null, 10000000L));     biddingStrategyConfiguration.setBids(new Bids[] {bid});     biddableAdGroupCriterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);     // Create operations.     AdGroupCriterionOperation operation = new AdGroupCriterionOperation();     operation.setOperand(biddableAdGroupCriterion);     operation.setOperator(Operator.SET);     AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] {operation};     // Update ad group criteria.     AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);     // Display ad group criteria.     for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {       if (adGroupCriterionResult instanceof BiddableAdGroupCriterion) {         biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterionResult;         CpcBid criterionCpcBid = null;         // Find the criterion-level CpcBid among the keyword's bids.         for (Bids bids : biddableAdGroupCriterion.getBiddingStrategyConfiguration().getBids()) {           if (bids instanceof CpcBid) {             CpcBid cpcBid = (CpcBid) bids;             if (BidSource.CRITERION.equals(cpcBid.getCpcBidSource())) {               criterionCpcBid = cpcBid;             }           }         }         System.out.printf(             "Ad group criterion with ad group ID %d, criterion ID %d, type "                 + "'%s', and bid %d was updated.%n",             biddableAdGroupCriterion.getAdGroupId(),             biddableAdGroupCriterion.getCriterion().getId(),             biddableAdGroupCriterion.getCriterion().getCriterionType(),             criterionCpcBid.getBid().getMicroAmount());       }     }   } } 

About a year ago, Google AdWords changed their name to Google Ads and now they complicated Google Ads API. Their official library doesn't work and I don't know where I should get information from.

My questions:

  1. How I can get all Google Ads scopes like here
  2. How LIST function for Google Ads looks like in JavaScript? (to get basics Google Ads user data) Link

Note:

Doesn't work anymore:

  • gapi.client.load('https://www.googleapis.com/discovery/v1/apis/adwords/v2/rest')
  • gapi.client.load('googleads', 'v3')
  • gapi.client.load('adwords', 'v2')
  • gapi.client.load('https://googleads.googleapis.com/v2/customers')

One working scope for Google Ads:

  • https://www.googleapis.com/auth/adwords

I am using the Google Oauth2 API to connect to Google Ads and become only one refresh token when my @gmail.com account has read access to two different Google Ads accounts.

I have the account a@gmail.com. This account has read access to the Google Ads accounts b@gmail.com and c@gmnail.com.

When I create two connections to Google Ads with the email a@gmail.com for the accounts b@gmail.com and c@gmail.com, then I receive only one refresh token, for the first connection and none refresh token for the second connection. Why? How can I manage this, to become 2 refresh tokens for each connection? The only way to become a refresh token for the second connection is to go to my account a@gmail.com and to decline the access to my app manually and connect again with c@gmail.com. But then b@gmail.com has no refresh token anymore.

code:

$oauth2 = new OAuth2(             [                 'authorizationUri' => $this->container->getParameter('oauth2.google.adwords.authorizationUri'),                 'tokenCredentialUri' => $this->container->getParameter('oauth2.google.adwords.tokenCredentialUri'),                 'redirectUri' => $this->container->getParameter('domain.system') . $this->container->getParameter(                         'oauth2.google.adwords.redirectUri.advertiser'                     ),                 'clientId' => $this->container->getParameter('oauth2.google.adwords.clientId'),                 'clientSecret' => $this->container->getParameter('oauth2.google.adwords.clientSecret'),                 'scope' => $this->container->getParameter('oauth2.google.adwords.scope')             ]         ); // Create a 'state' token to prevent request forgery.             // Store it in the session for later validation.             $randomState = sha1(openssl_random_pseudo_bytes(1024)) . '---' . $accountId;             $oauth2->setState($randomState);             // Redirect the user to the authorization URL.             $config = [                 // Set to 'offline' if you require offline access.                 'access_type' => 'offline',                 'approval_prompt' => 'force'             ];             // redirect to google ads             return new RedirectResponse($oauth2->buildFullAuthorizationUri($config));