[英]RCurl for use in Google Adwords
I'd like to download data pertaining to keywords straight into/from R. I understand that RCurl would most probably be the way to go, but I am not sure how to proceed with the task. 我想直接从/下载有关关键字的数据。我知道RCurl很可能是要走的路,但我不知道如何继续执行任务。 Perhaps anybody here could put me on the right track?
也许这里的任何人都可以让我走上正轨?
PS. PS。 I may slightly edit this question as answers pour in because I have some ideas of how I could possibly download Adwords data using R;
我可能会稍微编辑这个问题,因为我有一些关于如何使用R下载Adwords数据的想法; however, the ideas are unclear, and any answers would probably make them clearer.
然而,这些想法并不清楚,任何答案都可能使它们更清晰。
Many thanks. 非常感谢。
EDIT: My attempt 编辑:我的尝试
The following is what I tried until now. 以下是我到现在为止所尝试的内容。
1. apply getURL
on the login URL to identify the ids
of the Email and Password fields 1.在登录URL上应用
getURL
以识别电子邮件和密码字段的ids
require(RCurl)
loginURL<- "https://accounts.google.com/ServiceLogin?service=adwords"
ch<- getCurlHandle()
curlSetOpt(curl=ch,ssl.verifypeer=FALSE,cainfo=system.file("CurlSSL", "cacert.pem", package = "RCurl"),cookiejar="./cookies.txt",cookiefile="./cookies.txt",verbose=TRUE,header=TRUE,followlocation=TRUE,autoreferer=TRUE)
try1<- getURL(loginURL,curl=ch)
2. I identified what the ids
for the important fields (email & password) were 2.我鉴定一下
ids
的重要领域(电子邮件和密码)为
<div class="email-div">
<label for="Email"><strong class="email-label">Email</strong></label>
<input type="email" spellcheck="false"
name="Email" id="Email" value=""
>
</div>
<div class="passwd-div">
<label for="Passwd"><strong class="passwd-label">Password</strong></label>
<input type="password" name="Passwd" id="Passwd"
3. I then used the above fields to apply the postForm
function at the loginURL
in order to log into Google Adwords 3.然后我用上述领域应用
postForm
在功能loginURL
以登录到谷歌的Adwords
params<- list(
"Email"="myemail",
"Passwd"="mypassword",
"GALX"="3b6rR7Jvk30")
loggedIn<- postForm(loginURL,.params=params,curl=ch)
However, I have no idea how to verify that I have successfully logged in. 但是,我不知道如何验证我已成功登录。
Plus , the URL for Kyeword planner tool in Google Adwords UI is: 此外 ,Google Adwords用户界面中Kyeword规划工具的网址是:
https://adwords.google.com/ko/KeywordPlanner/Home?__c=XXXXXXXXXX&__u=XXXXXXXXXX&__o=cues
where the c= reflects the customer id
and the u= reflects the user id
. 其中c =反映
customer id
,u =反映user id
。 What I thought about doing, given this, was to log in using my browser, paste the URL shown above into R, and then try to find out the ids for fields that I will be of relevance to me, such as the id for the keywords text box
in the Keyword planner tool, to which I could possibly send keywords from R. 考虑到这一点,我想做的就是使用我的浏览器登录,将上面显示的URL粘贴到R中,然后尝试查找我将与我相关的字段的ID,例如
keywords text box
规划工具中的keywords text box
,我可以从中发送关键字。
But when I try to apply getURL
on the aforesaid website, I do not get the required/expected xml tags
or key value pairs
. 但是当我尝试在上述网站上应用
getURL
时,我没有获得所需/预期的xml tags
或key value pairs
。 Instead: 代替:
<html><head><noscript><meta http-equiv="refresh" content="0; URL=https://adwords.google.com/select/interstitial_short_js.html"></noscript></head><body><script type="text/javascript" language="javascript">var jsRedirect = true;var url = "/um/StartNewLogin?dst=/ko/KeywordPlanner/Home?__c%3D7857647860%26__u%3D4575929980%26__o%3Dcues";
if (self.document.location.hash) {url = url + ((url.indexOf('?') == -1)? '?' : '&') + "frag=" + self.document.location.hash.substring(1); }
window.location.assign(url);
</script> </body> </html>
This leads me to think that I am probably dealing with Javascript
or AJAX
here. 这让我觉得我可能在这里处理
Javascript
或AJAX
。 So, how to extract data from Javascript
or AJAX
using RCurl
, and is this the correct question to ask? 那么,如何使用
RCurl
从Javascript
或AJAX
提取数据,这是正确的问题吗?
Thanks & apologies for the lengthy edit. 感谢并为漫长的编辑道歉。
Have you seen our RAdwords package in the meantime? 你有没有看过我们的RAdwords套餐?
It provides an authentication process for R with the Adwords API and an interface to load data from the Adwords API directly into R . 它使用Adwords API为R提供身份验证流程,并将Adwords API中的数据直接加载到R中 。
Example code to load keyword data: 加载关键字数据的示例代码:
#install package from CRAN
install.packages('RAdwords')
#load package
library(RAdwords)
#start authentication process
google_auth <- doAuth()
#build statement object
body <- statement(select=c('AccountDescriptiveName','Date', 'CampaignName', 'AdGroupName','KeywordText', 'KeywordMatchType', 'Clicks', 'Cost'),
report="KEYWORDS_PERFORMANCE_REPORT",
start="20140320",
end="20140321")
#download data as data frame
data <- getData(clientCustomerId='xxx-xxx-xxxx',
google_auth = google_auth,
statement=body,
transformation = T)
#all available report types
reports()
#all available metrics of specific report type
metrics("KEYWORDS_PERFORMANCE_REPORT")
I don't have enough reputation to comment (ridiculous!), hence this answer. 我没有足够的声誉来评论(荒谬!),因此这个答案。
My answer pertains to your question's part on how to verify the result of logging in. I would do it this way: 我的回答与您的问题有关如何验证登录结果的部分。我会这样做:
loggedIn<- postForm(loginURL, .params=params, curl=ch)
info <- getCurlInfo(ch)
# 1) check the value of info$response.code here and act accordingly
# 2) you probably need the value to be 200 or between 200 and 300, but for more details
# on HTTP status codes, see this page: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.