使用keywordtool.io进行httr POST

时间:2018-02-06 18:30:54

标签: r post httr

我很难让httr使用我公司目前正在使用的API,对于我的生活,我无法理解为什么。

x <- c("Electronic cigarette",                                       
"Cloud-chasing electronic cigarette",                       
"Safety of electronic cigarettes",                            
"Electronic cigarette aerosol and liquid",                    
"Openvape",                                                   
"Blu eCigs",                                                  
"Regulation of electronic cigarettes",                        
"PAX Labs",                                                   
"Construction of electronic cigarettes",                      
"Vape shop",                                                  
"Hon Lik",                                                    
"Dragonite International Limited",                            
"Positions of medical organizations on electronic cigarettes",
"Evolv",                                                      
"List of vaping bans in the United States",                   
"VMR Products",                                               
"List of electronic cigarette brands",                        
"Electronic cigarettes in Australia",                         
"LOGIC electronic cigarette",                               
"VUSE electronic cigarette",                                
"NJOY",                                                       
"R. J. Reynolds Vapor Company",                               
"MarkTen",                                                    
"Vista Vapors",                                               
"Riccardo Polosa",                                            
"Ten Motives",
)

vars <- list(
keyword = as.character(x),
apikey = "apikeyhere",
metrics_location = "2826",
metrics_language = "en",
metrics_network = "googlesearchnetwork", 
metrics_currency = "USD",
output = "json"
)


res <- POST("https://api.keywordtool.io/v2/search/volume/google"
        , body = vars
        , encode = "json", verbose())

当我针对不同的指标位置(例如,2826是英国)执行此操作时,它只返回默认的美国数据。似乎是在列表的关键字部分读取数据,但忽略了其余部分。可以在此处找到API的文档(不幸的是,API已付款):https://keywordtool.io/api/documentation#examples

当我将其格式化为php脚本并通过终端运行时,我能够为美国和英国获得不同的结果,我似乎无法使其与httr一起使用。我们欢迎您的想法。

编辑:

将两个值放在列表中所需的两个参数,即使只有一个项目也是如此。我的理解力很差。

1 个答案:

答案 0 :(得分:-1)

参数似乎存在问题,metrics_location似乎被默认的GLOBAL / ENGLISH覆盖或未加载。 首先检查https://keywordtool.io/api。 然后只需在网址中添加:“ https://api.keywordtool.io/v2/search/volume/google ?metrics_location = [NUMBERS] 。对我有用。

相关问题