Posts tagged with google-ads-api

let startDate = '2020-01-01'; let endDate = new Date().toISOString().slice(0, 10).toString(); // "WHERE segments.date BETWEEN '2020-01-01' AND 'endDate' " 

Returns this error:

Exception: Call to GoogleAdsService.Search failed: Condition 'segments.date BETWEEN '2020-01-01' and 'endDate'' is invalid: BETWEEN operator must have exactly two values that are both numbers or both date strings in 'YYYY-MM-DD' format.

How can I set endDate to YESTERDAY?

I am facing this error on flutter native ads (android):

PlatformException(NativeAdError, Can't find NativeAdFactory with id: homeScreen, null, null)

google_mobile_ads: ^0.13.0 

this is my HomeScreenNativeAd.kt file

class HomeScreenNativeAd(val context: Context) : GoogleMobileAdsPlugin.NativeAdFactory{     override fun createNativeAd(             nativeAd: NativeAd,             customOptions: MutableMap<String, Any>?     ): NativeAdView {         val homeScreenNativeView = LayoutInflater.from(context)                 .inflate(R.layout.home_screen_native_ad, null) as NativeAdView         with(homeScreenNativeView) {             val attributionViewSmall =                     findViewById<TextView>(R.id.tv_home_item_native_ad_attribution_small)             val icon = findViewById<ImageView>(R.id.home_item_bg_image)             val image = nativeAd.icon             if (image != null) {                 attributionViewSmall.visibility = View.VISIBLE                 icon.setImageDrawable(image.drawable)             } else {                 attributionViewSmall.visibility = View.INVISIBLE             }             this.iconView = iconView             val adV =   findViewById<TextView>(R.id.adviser)             adV.text = nativeAd.advertiser             this.advertiserView =adV             val ctaButton =   findViewById<TextView>(R.id.home_screen_cta_button)             ctaButton.text = nativeAd.callToAction             this.callToActionView = ctaButton             val adDesc =   findViewById<TextView>(R.id.home_item_ad_desc)             adDesc.text = nativeAd.body             this.bodyView = ctaButton             val headlineView = findViewById<TextView>(R.id.home_item_ad_title)             headlineView.text = nativeAd.headline             this.headlineView = headlineView             setNativeAd(nativeAd)         }         return homeScreenNativeView     } } 

home_screen_native_ad.xml file

`

<com.google.android.gms.ads.nativead.NativeAdView     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent">     <FrameLayout         android:layout_width="match_parent"         android:layout_height="match_parent">         <RelativeLayout             android:orientation="vertical"             android:layout_width="wrap_content"             android:layout_height="160dp">             <FrameLayout                 android:layout_width="match_parent"                 android:background="#00ffffff"                 android:layout_height="140dp"/>             <RelativeLayout                 android:layout_width="match_parent"                 android:layout_height="190dp"                 android:layout_marginTop="16dp"                 android:layout_marginEnd="16dp"                 android:layout_marginBottom="16dp"                 android:gravity="start"                 android:orientation="horizontal">                 <ImageView                     android:id="@+id/home_item_bg_image"                     android:layout_width="60dp"                     android:layout_height="60dp"                     android:scaleType="centerCrop"                     android:layout_marginLeft="16dp"                     />                 <TextView                     android:id="@+id/home_item_ad_title"                     android:layout_width="220dp"                     android:layout_height="wrap_content"                     android:layout_marginLeft="10dp"                     android:layout_toRightOf="@+id/home_item_bg_image"                     android:ellipsize="end"                     android:lines="1"                     android:maxLines="1"                     android:textColor="#FFFFFFFF"                     android:textSize="20sp"                     tools:text="Headline" />                 <TextView                     android:id="@+id/adviser"                     android:layout_width="229dp"                     android:layout_height="wrap_content"                     android:layout_marginLeft="10dp"                     android:layout_marginTop="32dp"                     android:layout_toRightOf="@+id/home_item_bg_image"                     android:ellipsize="end"                     android:lines="1"                     android:maxLines="1"                     android:textColor="#FFFFFFFF"                     android:textSize="14sp"                     tools:text="Advertiser" />                 <TextView                     android:id="@+id/tv_home_item_native_ad_attribution_small"                     android:layout_width="35dp"                     android:layout_height="20dp"                     android:layout_marginLeft="10dp"                     android:layout_toRightOf="@+id/home_item_ad_title"                     android:background="@color/softOrange"                     android:gravity="center"                     android:lines="1"                     android:maxLines="1"                     android:text="Ad"                     android:textColor="#FFFF"                     android:textSize="12sp" />             </RelativeLayout>             <TextView                 android:id="@+id/home_item_ad_desc"                 android:layout_width="270dp"                 android:layout_height="40dp"                 android:layout_marginTop="85dp"                 android:ellipsize="end"                 android:lines="2"                 android:gravity="center_vertical"                 android:maxLines="2"                 android:textColor="#FFFFFFFF"                 android:textSize="14sp"                 android:layout_marginLeft="16dp"                 tools:text="Headline" />             <TextView                 android:id="@+id/home_screen_cta_button"                 android:layout_width="wrap_content"                 android:layout_marginLeft="10dp"                 android:layout_height="30dp"                 android:layout_toRightOf="@+id/home_item_ad_desc"                 android:layout_marginTop="100dp"                 android:text="INSTALL"                 android:gravity="center"                 android:ellipsize="end"                 android:lines="1"                 android:textColor="#FFF"                 android:maxLines="1"                 android:textSize="18sp"                 />         </RelativeLayout>     </FrameLayout> </com.google.android.gms.ads.nativead.NativeAdView>` 

MainActivity.kt

`class MainActivity : FlutterActivity(){     private val CHANNEL = "verified.cv/channel" //The channel name you set in your main.dart file     override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {         super.configureFlutterEngine(flutterEngine)         MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {             // Note: this method is invoked on the main thread.             call, result ->             if (call.method == "createNotificationChannel") {                 val argData = call.arguments as java.util.HashMap<String, String>                 val completed = createNotificationChannel(argData)                 if (completed == true) {                     result.success(completed)                 } else {                     result.error("Error Code", "Error Message", null)                 }             } else {                 result.notImplemented()             }         }         GoogleMobileAdsPlugin.registerNativeAdFactory(                 flutterEngine, "listTile", ListTileNativeAdFactory(context))         GoogleMobileAdsPlugin.registerNativeAdFactory(                 flutterEngine, "skillCard", SkillCardNativeFactory(context))         GoogleMobileAdsPlugin.registerNativeAdFactory(                 flutterEngine, "homeScreen", HomeScreenNativeAd(context))         GoogleMobileAdsPlugin.registerNativeAdFactory(                 flutterEngine, "feedItem", FeedItemNativeFactory(context))     }     override fun cleanUpFlutterEngine(flutterEngine: FlutterEngine) {         super.cleanUpFlutterEngine(flutterEngine)         // TODO: Unregister the ListTileNativeAdFactory         GoogleMobileAdsPlugin.unregisterNativeAdFactory(flutterEngine, "listTile")         GoogleMobileAdsPlugin.unregisterNativeAdFactory(flutterEngine, "skillCard")         GoogleMobileAdsPlugin.unregisterNativeAdFactory(flutterEngine, "homeScreen")         GoogleMobileAdsPlugin.unregisterNativeAdFactory(flutterEngine, "feedItem")     }     private fun createNotificationChannel(mapData: HashMap<String, String>): Boolean {         val completed: Boolean         if (VERSION.SDK_INT >= VERSION_CODES.O) {             // Create the NotificationChannel             val id = mapData["id"]             val name = mapData["name"]             val descriptionText = mapData["description"]             // val sound = "your_sweet_sound"             val importance = NotificationManager.IMPORTANCE_HIGH             val mChannel = NotificationChannel(id, name, importance)             mChannel.description = descriptionText             // val soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getApplicationContext().getPackageName() + "/raw/your_sweet_sound");             // val att = AudioAttributes.Builder()             //         .setUsage(AudioAttributes.USAGE_NOTIFICATION)             //         .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)             //         .build();             //mChannel.setSound(soundUri, att)             // Register the channel with the system; you can't change the importance             // or other notification behaviors after this             val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager             notificationManager.createNotificationChannel(mChannel)             completed = true         } else {             completed = false         }         return completed     } } ` 
 I/flutter ( 1409): ----------------FIREBASE CRASHLYTICS---------------- I/flutter ( 1409): PlatformException(NativeAdError, Can't find NativeAdFactory with id: homeScreen, null, null) I/flutter ( 1409): #0      StandardMethodCodec.decodeEnvelope package:flutter/…/services/message_codecs.dart:607 I/flutter ( 1409): #1      MethodChannel._invokeMethod package:flutter/…/services/platform_channel.dart:177 I/flutter ( 1409): <asynchronous suspension> I/flutter ( 1409): #2      NativeAd.load package:google_mobile_ads/src/ad_containers.dart:1033 I/flutter ( 1409): <asynchronous suspension> I/flutter ( 1409): ---------------------------------------------------- D/ACodec  ( 1409): dataspace changed to 0x10c40000 (R:2(Limited), P:4(BT601_6_525), M:3(BT601_6), T:3(SMPTE170M)) (

I'm trying to remove IP addresses from a campaign via the API. I'm able to add them fine using ipblockinfo and campaignCriterionOperation but I can't seem to remove it.

The build for the operation looks like :

 $campaignCriterion = new CampaignCriterion( [             'ip_block' => new IpBlockInfo( [                 'ip_address' => $item[ 'ip' ]             ] ),             'negative' => true, // setting it to negative             'campaign' => ResourceNames::forCampaign( $customerId, $item[ 'campaignId' ] )         ] ); 

and to remove it I'm using :

$campaignCriterionOperation->setRemove( $campaignCriterion ); 

Which is then sent via a mutateCampaignCriteria.

When I use the set remove I get a object to string error. So I looked into the SDK and saw that yes setRemove want's a resource output only as I'm guessing it's about removing the operation not actually removing the ip or criterion specified. Does anyone have any guidance on where to look or how to do a removal of an ip as Googles docs on this aren't very descriptive.

Inside the IPBlockInfo there is also a Clear IP address but this is purely to unset the variable in the object before sending the operation.

I need to make inactive assets linked to a specific ad, i.e. to get the same result through the api as in the google ads web interface. Example by following the link

I've tried it myself in two ways

  1. I wanted to try and delete the asset itself, but I found a description in the documentation that the asset cannot be deleted using AssetService because it does not support a remove operation
  2. Ok, I tried to remove an ad using AdGroupAdService using sample (using python but this is not crucial) but got an message about this operation not for an ad with type APP_AD message: "Cannot remove an adgroup ad with this ad type."

In the end, I found information that in order to stop an asset, the link between the asset and the ad has to be removed. But nowhere is there any example of what this is or how to do it. Any help with this problem would be greatly appreciated.

I couldn't run instrumental(UI) tests after Google Ads dependency implementation. The runner crashed every time; I tried to implement it to the dummy project because initially, I thought that the problem was in my project but it seemed not I got the same result on the dummy project, So merely my instrumental tests didn't run. I have inspected the Google Ads dependency and spotted that the root cause was google ads-lite which is used by the google ads library. I tried a few variants such as change runner, run it on x86, x64platforms, change lib version, changeGradle` version, change AGP version. But I can't find a solution.

Steps to reproduce:

Create a dummy project(runner: "androidx.test.runner.AndroidJUnitRunner") Run an instrumental test to make sure that was passed successfully implement com.google.android.gms:play-services-ads: 20.5.0(or latest version) Run an instrumental test it should be stuck because of the runner crash