douren7921 2017-04-12 22:54
浏览 102
已采纳

如何在github,php中获取特定文件

I would know if it's possible to download a specific files (json) from github to insert a directory without to download all the files via a zip.

I have this

   $json = @file_get_contents($this->GetGithubRepo() . '/' . $module_name . '/contents/' . $this->ModuleInfosJson . '?ref=master', true, $this->context );

This line read the json, I would to write the json on a directory. Objective is to create a cache and read the cache before to read on github.

Thank you

  • 写回答

1条回答 默认 最新

  • dongzhan5286 2017-04-13 00:07
    关注

    Github is not "in love" with this behavior, but I have an entire framework that runs on the same paradigm. I do, however, use the zip. You can hit the raw content following this pattern:

    https://raw.githubusercontent.com/YOURHANDLE/THE_REPO/THE_BRANCH/FILE/PATH/ETC
    

    Look for the "raw" option on a particular file when browsing.

    Here is a config file from one of my repo in a format similar to how you wish:

    https://raw.githubusercontent.com/datamafia/ShopifyETL/master/config.cfg

    should currently return

    [all]
    SHOPIFY_KEY=YOUR-SHOPIFY-API-KEY
    SHOPIFY_PASSWORD=YOUR-SHOPIFY-API-PW
    SHOPIFY_STORE=YOUR-SHOPIFY-STORE-DOES-NOT-EXIST
    SHOPIFY_BASE_URL=SHOPIFY_STORE.myshopify.com-or-custom-FQDN
    

    Pay attention to document type and encoding, these could trip you up. Your JSON may not be JSON via the header (should not be).

    One final problem, beyond encoding, is that of private accounts. Once private a big can of work will be put on your plate to auth in and see the data.

    The header, mildly changed:

    Date: Thu, 13 Apr 2017 00:02:48 GMT
    Via: 1.1 varnish
    Cache-Control: max-age=300
    Etag: "154ec087bc75e501a18e72d4e14a6f17bc2f706b"
    Connection: keep-alive
    X-Served-By: cache-dfw1840-DFW
    X-Cache: HIT
    x-cache-hits: 1
    X-Timer: S1492012345.3876515,VS0,VE0
    Vary: Authorization,Accept-Encoding
    Access-Control-Allow-Origin: *
    X-Fastly-Request-ID: XYZABCXYZABCXYZABCXYZABCXYZABC
    Expires: Thu, 13 Apr 2017 00:07:48 GMT
    Source-Age: 35
    

    Document type is "plain" (text), so some casting and checking will be important. There are tools in PHP to handle the incoming data and use as JSON. Good luck.

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

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题