Json 在R/R Studio中访问Shoothill API
嗨,我正在尝试使用R studio访问R中的Floodhill洪水警报API。 我不完全确定如何使用我拥有的API密钥登录,然后调用API 我成功地使用不同的API调用了API,例如Json 在R/R Studio中访问Shoothill API,json,r,api,rstudio,Json,R,Api,Rstudio,嗨,我正在尝试使用R studio访问R中的Floodhill洪水警报API。 我不完全确定如何使用我拥有的API密钥登录,然后调用API 我成功地使用不同的API调用了API,例如 library(jsonlite) jsondata <- fromJSON("http://api.wunderground.com/api/c86b0e891d592775/geolookup/conditions/q/IA/Cedar_Rapids.json")#access api names(js
library(jsonlite)
jsondata <- fromJSON("http://api.wunderground.com/api/c86b0e891d592775/geolookup/conditions/q/IA/Cedar_Rapids.json")#access api
names(jsondata)
summary(jsondata)
library(jsonlite)
jsondata从技术上讲,这不是一个完整的R答案,但他们在API提供程序页面上给出的示例在R中使用RCurl
包是100%可行的:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$apiKey = '<Your API Key>';
$url = 'https://apifa.shoothill.com/Account/APILogin/';
$postinfo = "apikey=".$apiKey."&persist=false";
$cookie_file_path = dirname(__FILE__) . "cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=1");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
$out = curl_exec($ch);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_URL, "https://apifa.shoothill.com/API/Floods");
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: application/json'));
$html = curl_exec($ch);
curl_close($ch);
echo $html;
return $html;
?>
OmegaHat非常详细地介绍了如何使用RCurl
,您应该能够很好地翻译上述内容。需要一段时间才能获得API密钥。在此之前,请参阅下面的非答案,以获得一些指导。谢谢-如果您能够提供帮助,我们将不胜感激。我发现我了解了RCurl的原理,但实现起来有点棘手。5分钟前确认了API密钥。将查看AM(嗯,AM代表缅因州)。感谢您的更新和迄今为止的帮助。您不应将CURLOPT\u SSL\u VERIFYHOST
设置为0。这是一个巨大的安全漏洞。这是从他们的网站上剪下来的