Twitter Ads API Wrapper for R

r

#1

Hi There,

just a quick question has anybody developed a Twitter Ads API wrapper for R? I am struggling to get access to the account from R script level.

Thanks,
GLD_data_team


#2

Hi,

Thanks for the feedback that you would prefer having this wrapper available.

Generally the OAuth layer is the same between Ads API and the public (REST) API. So I found this example, I hope it helps you: https://medium.com/@GalarnykMichael/accessing-data-from-twitter-api-using-r-part1-b387a1c7d3e


#3

Hi @JBabichJapan,

This is what I tried, with no success, I am using the credential associated with the app I created, and my app was listed for ads API, I can get it working through Twurl, but not in R.

my code:

library(twitteR)
library(ROAuth)
library(RCurl)
library(parsedate)
library(BBmisc)
library(httr)

appname <- “xxxxx”
api_key <- “xxxxxxx”
api_secret <- “xxxxxxxx”
access_token <- “xxxxxxx”
access_secret <- “xxxxxx”
account_id <- “xxxxxxx”

setup_twitter_oauth(api_key,api_secret, access_token, access_secret)

campaign_id <- itostr(18257572,base=36)

reach_campaign.request <- GET(“https://ads-api.twitter.com/1/stats/accounts/xxxxxxx/reach/campaigns?start_time=2018-06-10T00:00:00+01:00Z&campaign_ids=xxxxx&end_time=2018-06-15T00:00:00+01:00Z”,
query = list(granularity = “DAY”,
metric_groups = “ENGAGEMENT”,
placement = “ALL_ON_TWITTER”),
accept_json(),
config(token = access_secret))

Any ideas?

Thanks,
Gld_data_team


#4

Hi - first thing to check - you should call /3/ path instead of /1/ because version 1 has been deprecated. Is that not the error you were receiving though?