我正在编写一个简单的小部件,它可以呈现画布参与图,就像 github 上的一样。
它使用 http://github.com/[user]/[repo]/graphs/participation 上的数据
该小部件运行良好并且基本完成。我遇到的唯一问题是,当我尝试通过 XHR 从上述链接检索 json 数据时(而不是像以前那样只是复制并粘贴到小部件中),我遇到了同源访问控制问题。
有什么方法可以通过 XHR 或某些隐藏的 github api 功能来访问这些信息?
I am writing a simple widget that renders a canvas participation graph just like the one's on github.
It uses the data at http://github.com/[user]/[repo]/graphs/participation
The widget works great and is basically done. The only problem I have is when I try to retrieve the json data from the above link via XHR (rather than just copying and pasting into the widget as I have been), I run into the same origin access control problem.
Is there any way I can access this information at all, either via XHR or some hidden github api feature?
发布评论
评论(1)
我相信 Github 通过其 CORS .github.com/v3/" rel="nofollow">API。您还可以设置服务器端代理,通过该代理向同源页面发出 XHR 请求,然后该页面向 Github 发出服务器端请求。
要回答您有关代理的问题,是的,这非常简单。实际上,大约两年前我就使用 Python 和 Tornado 完成了这件事。我意识到这不是 PHP,但它读起来足够接近英语,可以让您了解它是如何工作的。这个特定的代理返回了原始要点。
然后它可以与类似的东西一起食用
I believe Github supports JSONP and CORS through its API. You could also setup a server-side proxy, through which XHR requests are made to a same-origin page which then does a server-side request to Github.
To answer your question about the proxy, yes it's very simple. I had actually done this exact thing about two years ago using Python and Tornado. I realize this isn't PHP, but it reads close enough to english to give you the idea about how it works. This particular proxy was returning a raw gist.
It can then be consumed with something along the lines of