[英]Using Excel to pull data from API
I am a complete novice when it comes to coding and would really appreciate your help in a project. 在编码方面,我是一个完整的新手,非常感谢您在项目中的帮助。
I want to pull data in Excel from an API offered by a website (resource URL: http://api.opensignal.com/v2/networkrank.json ). 我想从网站提供的API中提取Excel中的数据(资源URL: http : //api.opensignal.com/v2/networkrank.json )。
Can you please advice how should I go about it. 你能告诉我应该怎么做。 Or could you please help with a sample code.
或者,您可以帮助您提供示例代码。
Many thanks 非常感谢
I made VBA-Web (Excel-REST) for accessing webservices and APIs with Excel. 我制作了VBA-Web(Excel-REST),用于通过Excel访问Web服务和API。 While I encourage you to look into tutorials on how to perform web requests with Excel (look for XMLHTTPRequest), I've found it to be a little tricky to get started, especially if you're new to programming, so here is some sample code based on OpenSignal's example :
虽然我鼓励您查看有关如何使用Excel执行Web请求的教程(查找XMLHTTPRequest),但我发现开始时有点棘手,特别是如果您不熟悉编程,所以这里有一些示例基于OpenSignal示例的代码:
Sub GetNetworkRank(Latitude As Double, Longitude As Double)
' Create client for executing requests
Dim Client As New WebClient
Client.BaseUrl = "http://api.opensignal.com/v1/"
' Create specific request
Dim Request As New WebRequest
Request.Resource = "networkrank.json"
' Request.Method = WebMethod.HttpGet is default
' Request.Format = WebFormat.Json is default
Request.AddQuerystringParam "lat", Latitude
Request.AddQuerystringParam "lng", Longitude
' distance=20 -> 20 km around lat-lng -> 40km x 40km bounding box
Request.AddQuerystringParam "distance", 20
' network_id=3 -> 3G networks
Request.AddQuerystringParam "network_id", 3
Request.AddQuerystringParam "apikey", "YOUR_API_KEY"
' Get response from request
Set Response = Client.Execute(Request)
' -> GET http://api.opensignal.com/v1/networkrank.json?lat=...&lng=...&...
If Response.StatusCode = 200 Then
' Get network rank
' (json response is automatically parsed)
Response.Data("networkRank")("...")
Else
Debug.Print "Error: " & Response.StatusCode & " " & Response.Content
End If
End Sub
First pick a langage. 首先选择一个语言。 If you are a novice in programming, you can give Python a try.
如果您是编程新手,可以试试Python 。 It is not that hard to get started.
开始并不难。 Just follow a good Getting Started Guide .
只需按照良好的入门指南 。
Then find the libraries you need to connect to your systems. 然后找到连接到系统所需的库。 For example:
例如:
Try basic things (simple GET on the API, simple write in the Excel document). 尝试基本的东西(API上的简单GET,Excel文档中的简单写入)。 Make it work.
让它起作用。 Iterate.
重复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.