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 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据