2016-02-25 36 views
0

林在PHP和IM試圖讓一個腳本誰將會創造新倉庫,趕上了一份文件,我在我的電腦,並在這個新的存儲庫提交新的。這個腳本將在cmd中執行。我搜索github上的API和我已經下載任何文件夾下有一些文件,我安裝了一些事情作曲家,但我不能在我的PHP創建github上的一個新的實例。Github的API與PHP

我不知道這事,我花兩天時間在此,我不能寫一個函數與GitHub的交談。在github開發者的網站我什麼都不懂,我真的需要這樣做,而且我很迷茫。我使用PhpStorm 6.0.3。

我無法理解:

1中的API是一個有很多文件的文件夾?或者是在phpstorm中導入的圖書館?我怎麼把這個放在phpstorm中,我可以獲得方法並創建我的函數?

2-哪裏獲得與GitHub的API通話的方法呢?我在哪裏可以看到他們?在github開發者中,我什麼也不懂。

我看到了類似的問題,但不幫助我很多。 請幫我

編輯

我下載了一個API,我用的是作曲家要求,顯然一切都很好,但是當我執行一些文件來測試API,同樣的錯誤彈出。該程序不能找到項目中的一些文件,在同一個文件夾中。 例:PHP致命錯誤:接口 'Github上\阿比\ ApiInterface' 在d未找到:\ PHP-github上-API的主\ lib中\ Github上\阿比\ AbstractApi.php第15行

在anothers文件出現同樣的錯誤,我把「使用」 referecing,即時通訊試圖使用這些文件,但不工作。例如:使用Github \ Api \ ApiInterface;

編輯

此代碼將創建一個新的存儲庫嗎?當我執行這段代碼時,我得到上面的錯誤,類'Github \ Api \ AbstractApi'找不到,但是類在那裏。

類回購擴展AbstractApi { 公共函數來創建( $名稱, $描述= '', $主頁= '', $公衆= TRUE, $組織= NULL, $ hasIssues =假的, $ hasWiki =假, $ hasDownloads =假, $ teamId = NULL, $ autoInit =假 ){$ 路徑!= NULL == $組織? 'orgs /'.$ organization。'/ repos':'user/repos';'

 $parameters = array(
     'name'   => $name, 
     'description' => $description, 
     'homepage'  => $homepage, 
     'private'  => !$public, 
     'has_issues' => $hasIssues, 
     'has_wiki'  => $hasWiki, 
     'has_downloads' => $hasDownloads, 
     'auto_init'  => $autoInit 
    ); 

    if ($organization && $teamId) { 
     $parameters['team_id'] = $teamId; 
    } 

    return $this->post($path, $parameters); 
} 

}

感謝,

約翰。

+0

這是一個廣泛的問題。嘗試縮小到你面臨的問題。你在github文檔中不理解的是什麼? –

+0

謝謝,我編輯問題 –

+0

關於第一個問題,它看起來像你不知道[API](https://en.wikipedia.org/wiki/Application_programming_interface)是什麼。總之,一個API可以被視爲一個工具箱或一個服務,所以它不僅僅是一個包含大量文件的文件夾*,API是比你在代碼中調用/使用的函數。 –

回答

0

我完成了我的腳本,一切都做得正確,對於我的明顯問題抱歉,並感謝誰回答了我。我的代碼:

<?php 

include "vendor/autoload.php"; 

$client = new \Github\Client(); 
$username = "JohannLucas"; 
$password = "mypassword"; 

$method = Github\Client::AUTH_HTTP_PASSWORD; 
//authenticate 
$client->authenticate($username, $password, $method); 

//Apagar Repositório 
//$client->api('repo')->remove('JohannLucas', 'teste'); 

//Criar Repositório 
$client->api('repo')->create('olamundo', 'Repositorio criado com o github api', 'http://my-repo-homepage.org', true); 

//Commit 

$committer = array('name' => 'JohannLucas', 'email' => '[email protected]'); 
$path = "teste.txt"; 
$commitMessage = "Commit do teste.txt"; 

$content = "Olá Mundo!"; 
$branch = "master"; 
$repo = "olamundo"; 

$fileInfo = $client->api('repo')->contents()->create('JohannLucas', 'olamundo', $path, $content, $commitMessage, $branch, $committer); 

print_r("Foi!"); 

謝謝!

約翰