git - How to download a github json -


i have problem, try download json generated url

https://api.github.com/repos/xxxx/xxxx/contents/xxxxxxx?ref=master 

i have json result that

[   {     "name": "xxxx.png",     "path": "xxxx/xxxx.png",     "sha": "8b33da362caab310626daa2b70b232a98b38c6db",     "size": 136356,     "url": "https://api.github.com/repos/xxxx/xxxx/contents/xxxx/xxxx.png?ref=master",     "html_url": "https://github.com/xxxx/xxxx/blob/master/xxxx/xxxx.png",     "git_url": "https://api.github.com/repos/xxxx/xxxx/git/blobs/8b33da362caab310626daa2b70b232a98b38c6db",     "download_url": "https://raw.githubusercontent.com/xxxx/xxxx/master/moduleinfosjson/xxxx.png",     "type": "file",     "_links": {       "self": "https://api.github.com/repos/xxxx/xxxx/contents/xxxx/xxxx.png?ref=master",       "git": "https://api.github.com/repos/xxxx/xxxx/git/blobs/8b33da362caab310626daa2b70b232a98b38c6db",       "html": "https://github.com/xxxx/module_apxxxx/blob/master/xxxx/xxxx.png"     }   } ] 

i write does'nt work , have message : failed open stream: http request failed! http/1.0 403 forbidden

warning:    fopen([{"name":"xxxxxx.png","path":"xxxxxx/xxxxxxx.png","sha":".............. 

my directory in 777.

 $json = @file_get_contents($this->getgithubrepo() . '/' . $module_name . '/contents/'  . $this->moduleinfosjson  . '?ref=master', true, $this->context );     file_put_contents(oscom::getconfig('dir_root', 'shop') . $this->moduleinfosjson . '/cache/' . $module_name . '.json', fopen($json, 'r')); 

but if write code that, it's ok need information sha, git ..., that's need, not in case.

  $download = 'https://raw.githubusercontent.com/clicshoppingaddson/' . $module_name . '/master/' . $this->moduleinfosjson . '/' . $module_name . '.json';     file_put_contents(oscom::getconfig('dir_root', 'shop') . $this->moduleinfosjson . '/cache/' . $module_name . '.json', fopen($download, 'r')); 

thank you.

i found solution

   $local_file = oscom::getconfig('dir_root', 'shop') . $this->moduleinfosjson . '/cache/' . $module_name . '.json';         $remote_file = $this->getgithubrepo() . '/' . $module_name . '/contents/'  . $this->moduleinfosjson  . '?ref=master';          $ch = curl_init();         $fp = fopen ($local_file, 'w+');         $ch = curl_init($remote_file);         curl_setopt($ch, curlopt_returntransfer, 1);         curl_setopt($ch,curlopt_useragent,'mozilla/5.0 (windows; u; windows nt 5.1; en-us; rv:1.8.1.13) gecko/20080311 firefox/2.0.0.13');         curl_setopt($ch, curlopt_timeout, 50);         curl_setopt($ch, curlopt_file, $fp);         curl_setopt($ch, curlopt_followlocation, 1);         curl_setopt($ch, curlopt_encoding, "");         curl_exec($ch);         curl_close($ch);         fclose($fp); 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -