duandi6531 2017-05-05 03:43
浏览 71
已采纳

如何访问Github用户的原子提要以从项目中获取提交? 或替代

Hello i'm new in Laravel and programming in general.

I'm trying to do an app that tracks the commit history of my team projects on GitHub. I now that `git log` do this but the idea is to put this on a server and access from everywhere without manually executing the command (don't know if this is possible btw).

So, at the moment, for me the solution is to read the atom feed of an user member of the project. The thing is that -for obvious reasons- private repos are not accesible directly. The GitHub documentation says that them can be accessed with basic auth but at the momment i'm unable to do it. I've tried to test in on Postman even with Oath2 creating and app and conceding permissions but don't why it doesn't work.

Btw, sorry for my english. Thanks in advance :)

  • 写回答

1条回答 默认 最新

  • donglong9745 2017-05-05 06:09
    关注

    Github provides a public API for retrieving user events in json format.

    If you type this in a (unix) console:

    curl https://api.github.com/users/sea-reel/events
    

    …you get a list of my last public commits.

    To implement this with Laravel you can simply use file_get_contents() :

    Route::get('/commits/{username}', function($username)
    {
        $url = "https://username:password@api.github.com/users/{$username}/events";
        $json = json_decode(file_get_contents($url),true);
    
        dd($json);
    });
    

    To also access commits from private repos, you can use one of the various authentication methods provided by Github's API. Here I used basic auth, but you may find more secure to use OAuth and store secret keys instead of raw passwords.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘