Hi,

You would need to prepare the KeywordPlan which is structured as follows:
KeywordPlan
<https://developers.google.com/google-ads/api/reference/rpc/google.ads.googleads.v0.resources#google.ads.googleads.v0.resources.KeywordPlan>
KeywordPlanCampaign
<https://developers.google.com/google-ads/api/reference/rpc/google.ads.googleads.v0.resources#google.ads.googleads.v0.resources.KeywordPlanCampaign>
KeywordPlanAdGroup
<https://developers.google.com/google-ads/api/reference/rpc/google.ads.googleads.v0.resources#google.ads.googleads.v0.resources.KeywordPlanAdGroup>
KeywordPlanKeyword
<https://developers.google.com/google-ads/api/reference/rpc/google.ads.googleads.v0.resources#google.ads.googleads.v0.resources.KeywordPlanKeyword>.
You could check the release notes
<https://developers.google.com/google-ads/api/docs/release-notes#keyword_planning>
for more details. Please check the code snippet in Java for reference. Let
me know if you face any issues while trying this.

Thanks,
Sreelakshmi, Google Ads API Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

On 03/15/19 09:43:04 javaviln...@gmail.com wrote:

Hello Anthony,
I have been replicating C# code with java and been playing with object *KeywordPlanServiceClient *where successfully manage to get *KeywordPlan *required to run *ForecastMetrics
*( expect this object to provide required info)


// Here is how to create Object:
*KeywordPlan *

  private String CreateKeywordPlan(GoogleAdsClient googleAdsClient, long
customerId) {

        // get KeywordPlanService
        KeywordPlanServiceClient serviceClient =
googleAdsClient.getLatestVersion().createKeywordPlanServiceClient();

        //Create a keyword plan for next quarter forecast
        KeywordPlan keywordPlan = KeywordPlan.newBuilder()
                .setName(StringValue.newBuilder().setValue("Keyword plan
for trafic estimate #" + System.currentTimeMillis()))

.setForecastPeriod(KeywordPlanForecastPeriod.newBuilder().setDateInterval(KeywordPlanForecastInterval.NEXT_QUARTER).build())
                .build();

        KeywordPlanOperation operation =
KeywordPlanOperation.newBuilder().setCreate(keywordPlan).build();
        List<KeywordPlanOperation> operations = new ArrayList<>();
        operations.add(operation);

        // Add the keyword plan
        MutateKeywordPlansResponse response =
serviceClient.mutateKeywordPlans(String.valueOf(customerId), operations);

        // Display the results
        String keywordPlanResource=
response.getResults(0).getResourceName();
        System.out.println("Create Keyword plan: " + keywordPlanResource);

        return keywordPlanResource;
    }



// Here is how to create keywords Objects:  *ForecastMetrics*

 private void GenerateForecastMetrics(GoogleAdsClient googleAdsClient,
String keywordPlanResource) {
        KeywordPlanServiceClient kpServiceClient =
googleAdsClient.getLatestVersion().createKeywordPlanServiceClient();
        GenerateForecastMetricsResponse response =
kpServiceClient.generateForecastMetrics(keywordPlanResource);
        for (KeywordPlanKeywordForecast keywordPlanKeywordForecast :
response.getKeywordForecastsList()) {
            ForecastMetrics metrics =
keywordPlanKeywordForecast.getKeywordForecast();
            System.out.println(" Keyword ID: " +
keywordPlanKeywordForecast.getKeywordPlanAdGroupKeyword());
            System.out.println(" Estimated daily clicks: " +
metrics.getClicks());
            System.out.println(" Estimated daily impressions: " +
metrics.getImpressions());
            System.out.println(" Estimated average cpc (micros): " +
metrics.getCtr());
            System.out.println("----");
        }

    }


Problem i have that *KeywordPlan *does not hold Keywords and i do not know
how to link it. Object wish holds keywords looks like *KeywordPlanKeyword*,
how to import/add/assign it to the *KeywordPlan *

please let me know what objects needs to be created  and how they are
linking (*Pseudo-code*) to get info on keywords. Maybe there is a option to
avoid creating keyword plan and load list of keywords ?

Best Regards
Gintaras


--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
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/a4d83666-368e-483f-afa4-0b86756cf158%40googlegroups.com
<https://groups.google.com/d/msgid/adwords-api/a4d83666-368e-483f-afa4-0b86756cf158%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
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/ijlio1r8fg0000000ff3qk0003h5iuw74mj0e1h74o30c1g68qj4d1l%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
private void getForecastMetrics(GoogleAdsClient googleAdsClient, long 
customerId) {

    // get KeywordPlanService
    KeywordPlanServiceClient serviceClient = 
googleAdsClient.getLatestVersion().createKeywordPlanServiceClient();

    //Create a keyword plan for next quarter forecast
    KeywordPlan keywordPlan = KeywordPlan.newBuilder()
            .setName(StringValue.newBuilder().setValue("Keyword plan for trafic 
estimate #" + System.currentTimeMillis()))
            
.setForecastPeriod(KeywordPlanForecastPeriod.newBuilder().setDateInterval(KeywordPlanForecastInterval.NEXT_QUARTER).build())
            .build();

    KeywordPlanOperation operation = 
KeywordPlanOperation.newBuilder().setCreate(keywordPlan).build();
    List<KeywordPlanOperation> operations = new ArrayList<>();
    operations.add(operation);
    MutateKeywordPlansResponse response = 
serviceClient.mutateKeywordPlans(String.valueOf(customerId), operations);
    String keywordPlanResource= response.getResults(0).getResourceName();
    System.out.println("Create Keyword plan: " + keywordPlanResource);
   
    
  //Create a keyword plan campaign
    KeywordPlanCampaignServiceClient serviceCampaignClient = 
googleAdsClient.getLatestVersion().createKeywordPlanCampaignServiceClient();

    KeywordPlanCampaign keywordPlancampaign = KeywordPlanCampaign.newBuilder()
            .setName(StringValue.newBuilder().setValue("Keyword plan campaign 
for trafic estimate #" + System.currentTimeMillis()))
            .setKeywordPlan(StringValue.of(keywordPlanResource))
            .setCpcBidMicros(Int64Value.of(6000000l))
            .setKeywordPlanNetwork(KeywordPlanNetwork.GOOGLE_SEARCH)
            .build();

    KeywordPlanCampaignOperation operationCampaign = 
KeywordPlanCampaignOperation.newBuilder().setCreate(keywordPlancampaign).build();
    List<KeywordPlanCampaignOperation> operationsCampaign = new ArrayList<>();
    operationsCampaign.add(operationCampaign);
    MutateKeywordPlanCampaignsResponse responseCampaign = 
serviceCampaignClient.mutateKeywordPlanCampaigns(String.valueOf(customerId), 
operationsCampaign);
    String keywordPlanCampaignResource= 
responseCampaign.getResults(0).getResourceName();
    System.out.println("Create Keyword plan campaign: " + 
keywordPlanCampaignResource);
    
  //Create a keyword plan adgroup
    KeywordPlanAdGroupServiceClient serviceAdGroupClient = 
googleAdsClient.getLatestVersion().createKeywordPlanAdGroupServiceClient();

    KeywordPlanAdGroup keywordPlanAdgroup = KeywordPlanAdGroup.newBuilder()
            .setName(StringValue.newBuilder().setValue("Keyword plan adgroup 
for trafic estimate #" + System.currentTimeMillis()))
            .setKeywordPlanCampaign(StringValue.of(keywordPlanCampaignResource))
            .setCpcBidMicros(Int64Value.of(6000000l))
            .build();

    KeywordPlanAdGroupOperation operationAdgroup = 
KeywordPlanAdGroupOperation.newBuilder().setCreate(keywordPlanAdgroup).build();
    List<KeywordPlanAdGroupOperation> operationsAdgroup = new ArrayList<>();
    operationsAdgroup.add(operationAdgroup);
    MutateKeywordPlanAdGroupsResponse responseAdgroup = 
serviceAdGroupClient.mutateKeywordPlanAdGroups(String.valueOf(customerId), 
operationsAdgroup);
    String keywordPlanAdgroupResource= 
responseAdgroup.getResults(0).getResourceName();
    System.out.println("Create Keyword plan adgroup: " + 
keywordPlanAdgroupResource);
  
       
  //Create a keyword plan keyword
    KeywordPlanKeywordServiceClient servicekeywordClient = 
googleAdsClient.getLatestVersion().createKeywordPlanKeywordServiceClient();

    KeywordPlanKeyword keywordPlanKeyword = KeywordPlanKeyword.newBuilder()
            .setKeywordPlanAdGroup(StringValue.of(keywordPlanAdgroupResource))
            .setCpcBidMicros(Int64Value.of(6000000l))
            .setMatchType(KeywordMatchType.BROAD)
            .setText(StringValue.of("red velvet cake"))
            .build();

    KeywordPlanKeywordOperation operationKeyword = 
KeywordPlanKeywordOperation.newBuilder().setCreate(keywordPlanKeyword).build();
    List<KeywordPlanKeywordOperation> operationsKeyword = new ArrayList<>();
    operationsKeyword.add(operationKeyword);
    MutateKeywordPlanKeywordsResponse responseKeyword = 
servicekeywordClient.mutateKeywordPlanKeywords(String.valueOf(customerId), 
operationsKeyword);
    String keywordPlanKeywordResource= 
responseKeyword.getResults(0).getResourceName();
    System.out.println("Create Keyword plan keyword: " + 
keywordPlanKeywordResource);
    
      
    //generate forecast metrics
      GenerateForecastMetricsResponse forecastResponse = 
serviceClient.generateForecastMetrics(keywordPlanResource);
      for (KeywordPlanKeywordForecast keywordPlanKeywordForecast : 
forecastResponse.getKeywordForecastsList()) {
          ForecastMetrics metrics = 
keywordPlanKeywordForecast.getKeywordForecast();
          System.out.println(" Keyword ID: " + 
keywordPlanKeywordForecast.getKeywordPlanAdGroupKeyword());
          System.out.println(" Estimated daily clicks: " + metrics.getClicks());
          System.out.println(" Estimated daily impressions: " + 
metrics.getImpressions());
          System.out.println(" Estimated average cpc (micros): " + 
metrics.getCtr());
          System.out.println("----");
      }

  }
  • (Google... javavilnius
    • RE... googleadsapi-forumadvisor via AdWords API and Google Ads API Forum
      • ... javavilnius
        • ... googleadsapi-forumadvisor via AdWords API and Google Ads API Forum
          • ... javavilnius
            • ... googleadsapi-forumadvisor via AdWords API and Google Ads API Forum

Reply via email to