Im trying to use rgoogleads but it keeps asking me for authentication. I 
instead want to use python googleads library. Can someone please help me 
convert the below script to python?


# LINES BELOW ARE FOR TROUBLESHOOTING AUTHENTICATION
#install.packages("RCurl")
#require(devtools)
#install_github('jburkhardt/RAdwords')


# Credentials set up at https://console.developers.google.com under 
x...@gmail.com
# developer.token <-'xx'
# client.id <-"xx-xx.apps.googleusercontent.com"
# client.secret <-"xx"
library(rgoogleads)
gads_auth(email = 'h...@gmail.com')
gads_auth_configure(path = 'D:/ga_auth/app.json')
google_auth <- doAuth()
refreshToken(google_auth)

options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", 
package = "RCurl")))

data2 <- gads_get_report(
  resource = 'campaign',
  fields   = c('campaign.name',
               'segments.date',
               'metrics.clicks'),
  date_from   = "2021-01-08",
  date_to     = "2021-01-10",
  customer_id       = '801-xx-xxxx'
)
#--- DimAdWordsAd 
------------------------------------------------------------------------------------------

SelectFields = c( 
'AdGroupId','Date','CreativeFinalUrls','CreativeUrlCustomParameters','Description','Description1'
                  
,'Description2','DisplayUrl','Headline','HeadlinePart1','HeadlinePart2','Path1','Path2','Id','Labels'
                  
,'AdType','Status','DevicePreference','ImageAdUrl','ImageCreativeImageHeight','ImageCreativeImageWidth'
                  ,'ImageCreativeName')
ReportName = "AD_PERFORMANCE_REPORT"

DimAdWordsAd <- 
getAdwordsData(ReportName,SelectFields,adwordsStartDate,adwordsEndDate)

# Clean up the Final URL to match format in FINAL_URL_REPORT
DimAdWordsAd$FinalURL <- 
substr(DimAdWordsAd$FinalURL,3,nchar(DimAdWordsAd$FinalURL)-2)

# Rename Columns
colnames(DimAdWordsAd)[1] <- "AdwordsAdGroupId"
colnames(DimAdWordsAd)[2] <- "Date"
colnames(DimAdWordsAd)[3] <- "FinalUrl"
colnames(DimAdWordsAd)[4] <- "CustomParameter"
colnames(DimAdWordsAd)[5] <- "Description"
colnames(DimAdWordsAd)[6] <- "DescriptionLine1"
colnames(DimAdWordsAd)[7] <- "DescriptionLine2"
colnames(DimAdWordsAd)[8] <- "DisplayUrl"
colnames(DimAdWordsAd)[9] <- "Headline"
colnames(DimAdWordsAd)[10] <- "Headline1"
colnames(DimAdWordsAd)[11] <- "Headline2"
colnames(DimAdWordsAd)[12] <- "Path1"
colnames(DimAdWordsAd)[13] <- "Path2"
colnames(DimAdWordsAd)[14] <- "AdwordsAdId"
colnames(DimAdWordsAd)[15] <- "Labels"
colnames(DimAdWordsAd)[16] <- "AdType"
colnames(DimAdWordsAd)[17] <- "AdState"
colnames(DimAdWordsAd)[18] <- "DevicePreference"
colnames(DimAdWordsAd)[19] <- "ImageAdUrl"
colnames(DimAdWordsAd)[20] <- "ImageAdHeight"
colnames(DimAdWordsAd)[21] <- "ImageAdWidth"
colnames(DimAdWordsAd)[22] <- "ImageAdName"

# Clean up the ImageAdUrl
DimAdWordsAd$ImageAdUrl <- 
paste("https://tpc.googlesyndication.com/pageadimg/imgad?id=",DimAdWordsAd$ImageAdUrl)

# Get maxiumum date for each Ad. Use attributes from that date.
DimAdWordsAdUniqueKeys <- ddply(DimAdWordsAd, ~ AdwordsAdGroupId + 
AdwordsAdId, summarize, max = max(Date))
colnames(DimAdWordsAdUniqueKeys)[3] <- "Date"
DimAdWordsAd <- merge(DimAdWordsAdUniqueKeys,DimAdWordsAd, 
by=c("Date","AdwordsAdGroupId","AdwordsAdId"))

# Clean up missing data
DimAdWordsAd$FinalUrl[DimAdWordsAd$FinalUrl == ""] <- "Unknown"
DimAdWordsAd$CustomParameter[DimAdWordsAd$CustomParameter == " --"] <- NA
DimAdWordsAd$Description[DimAdWordsAd$Description == " --"] <- NA
DimAdWordsAd$DescriptionLine1[DimAdWordsAd$DescriptionLine1 == " --"] <- NA
DimAdWordsAd$DescriptionLine2[DimAdWordsAd$DescriptionLine2 == " --"] <- NA
DimAdWordsAd$DisplayUrl[DimAdWordsAd$DisplayUrl == " --"] <- NA
DimAdWordsAd$Headline[DimAdWordsAd$Headline == " --"] <- NA
DimAdWordsAd$Headline1[DimAdWordsAd$Headline1 == " --"] <- NA
DimAdWordsAd$Headline2[DimAdWordsAd$Headline2 == " --"] <- NA
DimAdWordsAd$Path1[DimAdWordsAd$Path1 == " --"] <- NA
DimAdWordsAd$Path2[DimAdWordsAd$Path2 == " --"] <- NA
DimAdWordsAd$Labels[DimAdWordsAd$Labels == " --"] <- NA
DimAdWordsAd$AdType[DimAdWordsAd$AdType == " --"] <- NA
DimAdWordsAd$AdState[DimAdWordsAd$AdState == " --"] <- NA
DimAdWordsAd$DevicePreference[DimAdWordsAd$DevicePreference == " --"] <- NA
DimAdWordsAd$ImageAdUrl[DimAdWordsAd$ImageAdUrl == " --"] <- NA
DimAdWordsAd$ImageAdUrl[DimAdWordsAd$ImageAdUrl == 
"https://tpc.googlesyndication.com/pageadimg/imgad?id=  --"] <- NA
DimAdWordsAd$ImageAdHeight[DimAdWordsAd$ImageAdHeight == " --"] <- NA
DimAdWordsAd$ImageAdWidth[DimAdWordsAd$ImageAdWidth == " --"] <- NA
DimAdWordsAd$ImageAdName[DimAdWordsAd$ImageAdName == " --"] <- NA

# Replce platform codes with names
DimAdWordsAd$DevicePreference[DimAdWordsAd$DevicePreference == "30000"] <- 
"Desktop"
DimAdWordsAd$DevicePreference[DimAdWordsAd$DevicePreference == "30001"] <- 
"High End Mobile"
DimAdWordsAd$DevicePreference[DimAdWordsAd$DevicePreference == "30002"] <- 
"Tablet"

# Drop date column
drops <- c("Date")
DimAdWordsAd <- DimAdWordsAd[ , !(names(DimAdWordsAd) %in% drops)]

# Get unique records
DimAdWordsAd <- unique(DimAdWordsAd)

# Write to file (over existing file)
DimAdWordsAdFile <- "DimAdWordsAd.csv"
file.exists(DimAdWordsAdFile) && file.remove(DimAdWordsAdFile)
write.csv(DimAdWordsAd, DimAdWordsAdFile, na = "", row.names = FALSE)

#--- DimAdWordsAdGroup 
-------------------------------------------------------------------------------------

SelectFields = c( 
'CampaignId','AdGroupId','AdGroupName','Date','AdGroupStatus')
ReportName = "ADGROUP_PERFORMANCE_REPORT"

DimAdWordsAdGroup <- 
getAdwordsData(ReportName,SelectFields,adwordsStartDate,adwordsEndDate)

# Rename Columns
colnames(DimAdWordsAdGroup)[1] <- "AdwordsCampaignId"
colnames(DimAdWordsAdGroup)[2] <- "AdwordsAdGroupId"
colnames(DimAdWordsAdGroup)[3] <- "AdGroup"
colnames(DimAdWordsAdGroup)[4] <- "Date"
colnames(DimAdWordsAdGroup)[5] <- "AdGroupState"

# Get maxiumum date for each Ad. Use attributes from that date.
DimAdWordsAdGroupUniqueKeys <- ddply(DimAdWordsAdGroup, ~ AdwordsAdGroupId 
+ AdwordsCampaignId, summarize, max = max(Date))
colnames(DimAdWordsAdGroupUniqueKeys)[3] <- "Date"
DimAdWordsAdGroup <- merge(DimAdWordsAdGroupUniqueKeys,DimAdWordsAdGroup, 
by=c("Date","AdwordsAdGroupId","AdwordsCampaignId"))

# Drop Date column
drops <- c("Date")
DimAdWordsAdGroup <- DimAdWordsAdGroup[ , !(names(DimAdWordsAdGroup) %in% 
drops)]

# Get unique AdGroupID and AdGroupName. Should already be unique. But just 
in case.
DimAdWordsAdGroup <- unique(DimAdWordsAdGroup)

# Write to file (over existing file)
DimAdWordsAdGroupFile <- "DimAdWordsAdGroup.csv"
file.exists(DimAdWordsAdGroupFile) && file.remove(DimAdWordsAdGroupFile)
write.csv(DimAdWordsAdGroup,DimAdWordsAdGroupFile, na = "", row.names = 
FALSE)
refreshToken(google_auth)

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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/64bca2dc-17fc-4274-a7ac-200efbb7dff0n%40googlegroups.com.
  • Ca... J T
    • ... 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum

Reply via email to