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

如何在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 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?