Hi,
   When I try to add keywords for a campaign through Google ads Api. I'm
getting the below error. Could you help me with this?

Error:

com.google.ads.googleads.v10.errors.GoogleAdsException: errors {
  error_code {
    context_error: OPERATION_NOT_PERMITTED_FOR_CONTEXT
  }
  message: "The operation is not allowed for the given context."
  trigger {
    string_value: "DISPLAY(DISPLAY_FULL_AUTOMATION)"
  }
  location {
    field_path_elements {
      field_name: "operations"
      index: 0
    }
    field_path_elements {
      field_name: "create"
    }
    field_path_elements {
      field_name: "keyword"
    }
  }
}
request_id: "qJgBolK31HDNQLhsvVP1Jw"

at
com.google.ads.googleads.v10.errors.GoogleAdsException$Factory.createException(GoogleAdsException.java:42)
at
com.google.ads.googleads.v10.errors.GoogleAdsException$Factory.createException(GoogleAdsException.java:34)
at
com.google.ads.googleads.lib.stubs.exceptions.BaseGoogleAdsException$Factory.createGoogleAdsException(BaseGoogleAdsException.java:105)
at
com.google.ads.googleads.lib.callables.GoogleAdsExceptionTransformation.transform(GoogleAdsExceptionTransformation.java:39)
at
com.google.ads.googleads.lib.stubs.callables.ExceptionTransformingUnaryCallable$ExceptionTransformingFuture.onFailure(ExceptionTransformingUnaryCallable.java:82)
at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:68)
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1126)
at
com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
at
com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:902)
at
com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:813)
at
com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:677)
at
com.google.api.gax.retrying.BasicRetryingFuture.handleAttempt(BasicRetryingFuture.java:200)
at
com.google.api.gax.retrying.CallbackChainRetryingFuture$AttemptCompletionListener.handle(CallbackChainRetryingFuture.java:135)
at
com.google.api.gax.retrying.CallbackChainRetryingFuture$AttemptCompletionListener.run(CallbackChainRetryingFuture.java:117)
at
com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
at
com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:902)
at
com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:813)
at
com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:677)
at
com.google.api.core.AbstractApiFuture$InternalSettableFuture.setException(AbstractApiFuture.java:95)
at
com.google.api.core.AbstractApiFuture.setException(AbstractApiFuture.java:77)
at
com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:97)
at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:68)
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1126)
at
com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
at
com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:902)
at
com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:813)
at
com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:677)
at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:563)
at
io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:533)
at
io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
at
io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
at
io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
at
com.google.ads.googleads.lib.logging.LoggingInterceptor$1$1.onClose(LoggingInterceptor.java:113)
at
io.grpc.internal.DelayedClientCall$DelayedListener$3.run(DelayedClientCall.java:463)
at
io.grpc.internal.DelayedClientCall$DelayedListener.delayOrExecute(DelayedClientCall.java:427)
at
io.grpc.internal.DelayedClientCall$DelayedListener.onClose(DelayedClientCall.java:460)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:557)
at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:69)
at
io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:738)
at
io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:717)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Suppressed: com.google.api.gax.rpc.AsyncTaskException: Asynchronous task
failed
at
com.google.api.gax.rpc.ApiExceptions.callAndTranslateApiException(ApiExceptions.java:57)
at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112)
at
com.google.ads.googleads.v10.services.AdGroupCriterionServiceClient.mutateAdGroupCriteria(AdGroupCriterionServiceClient.java:223)
at
com.google.ads.googleads.v10.services.AdGroupCriterionServiceClient.mutateAdGroupCriteria(AdGroupCriterionServiceClient.java:185)
at clevermoe_service.AddKeywords.runExample(AddKeywords.java:164)
at clevermoe_service.AddKeywords.main(AddKeywords.java:92)
Caused by: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Request
contains an invalid argument.
at io.grpc.Status.asRuntimeException(Status.java:535)
... 17 more

Code:

public static void main(String[] args) throws FileNotFoundException,
IOException {
// AddKeywordsParams params = new AddKeywordsParams();
// if (!params.parseArguments(args)) {

// Either pass the required parameters for this example on the command
line, or
// insert them
// into the code here. See the parameter class definition above for
// descriptions.
customerId = Long.parseLong("5114451929");
adGroupId = Long.parseLong("135135826529");

// Optional: Specify a keywordText here, or the default specified below
will be
// used.
// params.keywordText = "INSERT_KEYWORD_TEXT_HERE";
// }

// if (params.keywordText == null) {
keywordText = DEFAULT_KEYWORD_TEXT;
// }

GoogleAdsClient googleAdsClient = null;
googleAdsClient =getGoogleAdsClient();
System.out.println(googleAdsClient);

try {
new AddKeywords().runExample(googleAdsClient, customerId, adGroupId,
keywordText);
} catch (GoogleAdsException gae) {
// GoogleAdsException is the base class for most exceptions thrown by an API
// request.
// Instances of this exception have a message and a GoogleAdsFailure that
// contains a
// collection of GoogleAdsErrors that indicate the underlying causes of the
// GoogleAdsException.
System.err.printf("Request ID %s failed due to GoogleAdsException.
Underlying errors:%n",
gae.getRequestId());
int i = 0;
for (GoogleAdsError googleAdsError :
gae.getGoogleAdsFailure().getErrorsList()) {
System.err.printf("  Error %d: %s%n", i++, googleAdsError);
}
System.exit(1);
}
}

/**
* Runs the example.
*
* @param googleAdsClient the Google Ads API client.
* @param customerId      the client customer ID.
* @param adGroupId       the ad group ID.
* @param keywordText     the keyword text to add.
* @throws GoogleAdsException if an API request failed with one or more
service
*                            errors.
*/
private void runExample(GoogleAdsClient googleAdsClient, long customerId,
long adGroupId, String keywordText) {
/*ClevermoeAdDaoImpl clevermoeAdDao = new ClevermoeAdDaoImpl();
ClevermoeCampaignEntity clevermoeCampaign = clevermoeAdDao
.findCampaignEntityByCampaignIdFromApp("2f31577e-11e9-42bc-8dd8-0887bbd7e110");
List<String> youtubeAndManualKeyword = new ArrayList<String>();
Collection<ManualTopicsList> manualTopicsCollection =
clevermoeCampaign.getManualTopics();
Iterator<ManualTopicsList> manualTopicItr =
manualTopicsCollection.iterator();
while (manualTopicItr.hasNext()) {
ManualTopicsList manualTopic = manualTopicItr.next();
if (manualTopic.getSocialMedia().equalsIgnoreCase("youtube")) {
youtubeAndManualKeyword.add(manualTopic.getKeyword());
}
}*/
/*youtubeAndManualKeyword.addAll(clevermoeCampaign.getYoutubeKeywords());
Iterator<String> iterator = youtubeAndManualKeyword.iterator();
 int youtubeKeywordPercentage = 0;
int youtubeKeywordsPassed = 0;
while (iterator.hasNext()) {
youtubeKeywordsPassed = youtubeKeywordsPassed + 1;
try {
youtubeKeywordPercentage = (int) (((float) youtubeKeywordsPassed /
youtubeAndManualKeyword.size())
* 100);
} catch (Exception e) {
e.printStackTrace();
}
String keyword = iterator.next();*/

// Configures the keywordText text and match type settings.
System.out.println(googleAdsClient);
KeywordInfo keywordInfo =
KeywordInfo.newBuilder().setText(keywordText).setMatchType(KeywordMatchType.BROAD)
.build();
String adGroupResourceName = ResourceNames.adGroup(5114451929l,
137075941347l);
// String adGroupResourceName =
"customers/5114451929/adGroups/134696137358";
System.out.println(adGroupResourceName);
// Constructs an ad group criterion using the keywordText configuration
above.
AdGroupCriterion criterion =
AdGroupCriterion.newBuilder().setAdGroup(adGroupResourceName)
.setStatus(AdGroupCriterionStatus.ENABLED).setKeyword(keywordInfo).build();

AdGroupCriterionOperation op =
AdGroupCriterionOperation.newBuilder().setCreate(criterion).build();
try {
AdGroupCriterionServiceClient agcServiceClient =
googleAdsClient.getLatestVersion()
.createAdGroupCriterionServiceClient();
MutateAdGroupCriteriaResponse response = null;
try {
response =
agcServiceClient.mutateAdGroupCriteria(Long.toString(customerId),
ImmutableList.of(op));
System.out.printf("Added %d ad group criteria:%n",
response.getResultsCount());
} catch (Exception e) {
e.printStackTrace();

}

for (MutateAdGroupCriterionResult result : response.getResultsList()) {
System.out.println(result.getResourceName());
}
agcServiceClient.shutdown();
} catch (Exception e) {
e.printStackTrace();

}
//}

}

public static GoogleAdsClient getGoogleAdsClient() {
GoogleAdsClient googleAdsClient =null;
try {
UserCredentials credentials =
      UserCredentials.newBuilder()
       .setClientId("
1053534245707-31dkmhd7t8m60cjj6mnuaf2b85cd5ibm.apps.googleusercontent.com")
      .setClientSecret("fxIszb7RkR66jDXV3oAVH-mJ")

.setRefreshToken("1//06MwS0EmDsUeZCgYIARAAGAYSNwF-L9Irf7HGt0MVZc_Yb382P-X2BcpmpvasAYhLGhNU4N3pH_GvZlvtnpl85_Atx010pfqVcOg")
         .build();
googleAdsClient =
GoogleAdsClient.newBuilder().setCredentials(credentials).setLoginCustomerId(5114451929l).setDeveloperToken("OZCfEMajUIwCIU0n9CeoOg").build();
return googleAdsClient;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return googleAdsClient;
}
}

Thanks & Regards,
Vibeeshnan A.

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/CAHW9OWn-iEdShqdyi1TRuUP-vnZboNFnLKvQXoCrpgzC6Uk9-Q%40mail.gmail.com.

Reply via email to