将Mashape与R一起使用 [英] Use Mashape with R

查看:101
本文介绍了将Mashape与R一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Mashape平台来使用R访问不同的API(例如epguides或pipl).我可以直接使用原始的API,但是习惯Mashape似乎是一个不错的投资,因为它提供了对许多其他API的统一访问.

I'm trying to use the Mashape platform to access to different APIs with R (e.g. epguides or pipl). I could use directly the original APIs, but getting used to Mashape seems to be a good investment since it provides a unified access to a whole lot of other APIs.

但是有两个问题:

  1. Mashape没有提供任何R教程.我尝试使用httr包查询Mashape,但直到那里都没有成功. 如何使用R查询Mashape?;
  2. 据我测试,Mashape 似乎上的大多数API端点都不响应(即使在平台提供的测试页面上). Mashape对于每个托管API真的可靠吗?
  1. Mashape doesn't provide any R tutorial. I tried the httr package to query Mashape but no success until there. How to query Mashape with R ? ;
  2. As far as I tested, most APIs endpoint on Mashape seem not to respond (even on the testing page provided by the platform). Is Mashape really reliable for every hosted API ?

推荐答案

好问题Gratien,

Great question Gratien,

下面是一个代码片段,可以帮助您入门:

Here is a code snippet to get you started:

查询天气API以获取下周在加利福尼亚州洛杉矶的天气预报!

Querying the weather API for the weather forecast over the next week in Los Angeles, California!

请记住要使用您自己的X-Mashape-Key进行更改:)

Remember to change the X-Mashape-Key with your own :)

#imports an http R library
library(httr)

#perform a GET request on the URL, with two headers and store in a resp variable
resp <- GET("https://george-vustrey-weather.p.mashape.com/api.php?location=Los+Angeles", add_headers("X-Mashape-Key" = "MASHAPE-OWN-KEY","Accept" = "application/json"))

#Prints the headers
headers(resp)

#Prints the content of the response
str(content(resp))

希望这会有所帮助!

这篇关于将Mashape与R一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆