Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于谷歌Adwords的RCurl_R_Google Ads Api_Rcurl - Fatal编程技术网

用于谷歌Adwords的RCurl

用于谷歌Adwords的RCurl,r,google-ads-api,rcurl,R,Google Ads Api,Rcurl,我想直接从R中下载与关键字相关的数据。我知道RCurl很可能是一种方式,但我不确定如何继续执行该任务。也许这里的任何人都能让我走上正轨 另外,我可能会在答案蜂拥而至时对这个问题稍加修改,因为我对如何使用R下载Adwords数据有一些想法;然而,这些想法还不清楚,任何答案都可能让它们更加清晰 非常感谢 编辑:我的尝试 以下是我迄今为止一直尝试的内容 1。在登录URL上应用getURL,以识别电子邮件和密码字段的ID require(RCurl) loginURL<- "https://ac

我想直接从R中下载与关键字相关的数据。我知道RCurl很可能是一种方式,但我不确定如何继续执行该任务。也许这里的任何人都能让我走上正轨

另外,我可能会在答案蜂拥而至时对这个问题稍加修改,因为我对如何使用R下载Adwords数据有一些想法;然而,这些想法还不清楚,任何答案都可能让它们更加清晰

非常感谢


编辑:我的尝试

以下是我迄今为止一直尝试的内容

1。在登录URL上应用
getURL
,以识别电子邮件和密码字段的
ID

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)
3.然后,我使用上述字段在
loginURL
中应用
postForm
功能,以登录Google Adwords

params<- list(
"Email"="myemail",
"Passwd"="mypassword",
"GALX"="3b6rR7Jvk30")

loggedIn<- postForm(loginURL,.params=params,curl=ch)
其中c=反映
客户id
,u=反映
用户id
。考虑到这一点,我想做的是使用我的浏览器登录,将上面显示的URL粘贴到R中,然后尝试找出与我相关的字段的id,例如关键字规划器工具中的
关键字文本框的id,我可以从R向其发送关键字

但是,当我尝试在上述网站上应用
getURL
时,我没有获得所需/预期的
xml标记
键值对
。相反:

<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>
var jsRedirect=true;var url=“/um/StartNewLogin?dst=/ko/KeywordPlanner/Home?uu c%3D7857647860%26_u%3D4575929980%26_uo%3Dcues”;
if(self.document.location.hash){url=url+((url.indexOf('?'))==-1)?'?':'&')+“frag=“+self.document.location.hash.substring(1);”
window.location.assign(url);
这让我想到我可能在这里处理
Javascript
AJAX
。 那么,如何使用
RCurl
Javascript
AJAX
提取数据,这是正确的问题吗


感谢并为冗长的编辑致歉。

我没有足够的声誉来评论(荒谬!),因此我给出了这个答案

我的回答与您关于如何验证登录结果的问题有关。我会这样做:

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
loggedIn你看到我们的包裹了吗

它使用Adwords API为R提供一个身份验证过程,并提供一个接口将数据从Adwords API直接加载到R

加载关键字数据的示例代码:

#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")
#从CRAN安装软件包
install.packages('RAdwords'))
#加载包
图书馆(RAdwords)
#启动身份验证过程

google_auth为此目的,为多种语言(Python、Java、Ruby等)提供了一个google Adwords API,您可以尝试使用一些帮助程序库将R与这些API中的一个接口,或者在csv中本地下载数据并将其导入R@LucaFiaschi非常感谢。事实上,这就是我这些天在做的事情。这对我来说有点难,因为我相对来说是个初学者,但希望我能成功。当我这样做的时候,我会把我的努力与这个问题联系起来,以帮助其他用户。@info_seekeR,你成功了吗?@davidernburg不幸的是,没有,从那以后我一直远离这个任务。我正在寻找能够提供帮助的合作者,但这只是一个旁白。那太糟糕了,我也在寻找解决方案。谢谢!为了您和其他用户的信息,我正在尝试使用R访问Adwords(就像其他人对Google Analytics所做的那样),如果我成功了,我将在这里发布我的代码。
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
#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")