In my business, I used twitter-ads to hit the API of the Twitter ad distribution management screen. I'm too new to Ruby and it was pretty tough, so I'll make a note of it.
twitter-ads version is 7.
It doesn't start without making this.
require 'twitter-ads' # initialize the client client = TwitterAds::Client.new( CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET )
Looking at the quick start on github.
# load the advertiser account instance account = client.accounts('c3won9gy')
There is, but the ID to pass there? What is it? It will be a story. As a result of various investigations
client.accounts.each do |v| p v.id end
If I did it like this, there was one such thing, so I had to give it the ID that came out there.
Use the ʻaccount` obtained above.
account.campaigns.each do |v| p "=====================" p v.id p v.reasons_not_servable p v.servable p v.deleted p v.created_at p v.updated_at p v.name p v.funding_instrument_id p v.end_time p v.start_time p v.entity_status p v.currency p v.standard_delivery p v.daily_budget_amount_local_micro p v.total_budget_amount_local_micro p v.to_delete p "=====================" end
If you do this, a list of campaigns will appear. (If you know how to get all the values in one line without ping one by one like this ...)
If you want to create an object only for a specific campaign,
campaign = account.campaigns('1m5bbbb')
Generate it like this (the ID to be passed is the value that came out in the above
You can get the campaign name like this.
campaign.name = "MADOKA" campaign.save
If you do, you can change the campaign name. I'm full of happiness.
This also outputs the ad group held by ʻaccount
, so use ʻaccount.
Now you can get a list of ad groups.
This also uses ʻaccount`.
account.tailored_audiences.each do |v| p "===========" p v.id p v.name p v.list_type p v.audience_size p v.audience_type p v.metadata p v.partner_source p v.reasons_not_targetable p v.targetable p v.targetable_types p "===========" end
Up to this point, I have somehow grasped the atmosphere of the acquisition system.
From here, I will write more practical usage.
line_item = account.line_items('1abcd')
You can get it at.
So, with this acquired
line_item.targeting_criteria.each do |target| if target.targeting_type == 'TAILORED_AUDIENCE' then p account.tailored_audiences(target.targeting_value).name end end
I feel like this.
line_item.targeting_criteria.each do |target| if target.targeting_type == 'TAILORED_AUDIENCE' then target.delete! end end
This was a lot of work,
tc = TwitterAds::TargetingCriteria.new(account) tc.line_item_id = 'ID of the ad group to be linked' tc.targeting_value = 'Tailored Audience ID you want to associate(value)' tc.targeting_type = 'TAILORED_AUDIENCE'This is fixed and you can put this in tc.save
It was like that.
Regarding tying. Creating a TA (Taylored Audience) doesn't immediately put you in "ready" status, so After creating it, you need to periodically go to see the TA in batch, check that the status is "targetable", and build a logic called linking.
It was a pain to understand how to use this SDK, but once I understood it, all I had to do was write it, so it was fun.
It's like that today.