2016-06-01 7 views
0

JSフィドルの値を返すされていません:https://jsfiddle.net/o1fb31z6/3/のGitHub APIは、ユーザー

わかりましたので、私は組織のための簡単な小さなプロジェクトをやっています。

しかし、ここで問題が発生します.Github APIの検索部分を使用してこのユーザーにクエリを実行すると、何も返されません。ユーザー名を調整すると値が返されるため、コードが機能することがわかります。誰でもこの問題がありますか?

上記のクエリでは、値を返すようにもなっていますが、情報の一部はオフです(フォークカウント)。

app.html:

<!doctype html> 
<html> 
    <head> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script> 
    <meta charset="utf-8"> 
    <meta http-equiv="Content-Type" content="text/html"> 
    <title>Github API Webapp using AngularJS</title> 
    </head> 

    <body ng-app="app"> 
    <div data-ng-controller='GitHubCtrl' data-ng-init='getGitInfo()'>  
     <h1>Simple Github API Webapp</h1> 
     <p>Search for a particular repo</p> 
     <input type="text" ng-model="repoName" placeholder="Github repo name...">  
     <a href="#" ng-click="searchGitRepos()">Find Repos</a> 
     <div ng-show='repoSearched'> 
     <p><strong>Repos found by search:</strong></p> 
     <ul ng-repeat='result in results'> 
      <li><a href="{{result.html_url}}" target="_blank"> {{result.name}} </a></li> 
      <li>User:{{result.owner.login}}</li> 
     </ul> 
     </div> 
     <div> 
     <h2>User: {{user.name}} 
      <span class="smallname"><a href="{{user.html_url}}" target="_blank"> {{user.login}} </a></span> 
     </h2> 
     </div>   
     <div> 
     <a href="{{ user.html_url }}" target="_blank"> 
     <img src="{{ user.avatar_url }}" width="80" height="80" alt="{{ user.login }}"></a> 
     </div> 
     <div ng-show="reposFound"> 
     <p><strong>Repos List:</strong></p> 
     <ul ng-repeat="repo in repos"> 
      <li><a href="{{repo.html_url}}" target="_blank"> {{repo.name}} </a></li> 
      <li>Forks Count: {{repo.forks_count}}</li> 
      <li>Created at:{{repo.created_at}}</li> 
      <li>Language: {{repo.language}}</li> 
     </ul> 
     </div> 

    </div> <!-- End of controller div --> 

    <script src='app.js'></script> 
    </body> 
</html> 

app.js:https://github.com/JohnnyTheTank/angular-github-api-factory

angular.module('app',[]).controller('GitHubCtrl', GitHubCtrl); 
function GitHubCtrl($scope, $http) { 
    // Set the default user here 
    $scope.username = 'aipub'; 
    // getGitInfo queries the Github api for user information and public repositories 
    $scope.getGitInfo = function() { 
     // This API call searches for logo of our user. 
     $http.get("https://api.github.com/users/" + $scope.username).success(function (data) { 
      $scope.user = data; 
     }); 
     // This API call searches for the repos of the user 
     $http.get("https://api.github.com/users/" + $scope.username + "/repos").success(function (data) { 
      nameFormatter(data); 
      $scope.repos = data; 
      $scope.reposFound = data.length > 0; 
     }); 
    } 
    // comment about function below 
    $scope.searchGitRepos = function() { 
     $http.get("https://api.github.com/search/repositories?q=" + $scope.repoName + "+in:name+user:" + $scope.username).success(function (data) { 
     $scope.results = data.items; 
     $scope.repoSearched = data.items.length > 0; 
     }); 
    } 
} 

// *args: array of objects of any length greater than 0. Capitalizes the name string of the each object 
// in the array by splitting the words into their individual components, excluding if the words are 
// 'python' or 'mongo'. 
    function nameFormatter(data) { 
    for (var i=0; i < data.length; i++) { 
     var formatName = data[i].name.split('-'); 
     for (var j=0; j < formatName.length; j++) { 
     if (!(formatName[j] === 'python' || formatName[j] === 'mongo')) { 
      formatName[j] = formatName[j].charAt(0).toUpperCase() + formatName[j].substr(1); 
     } 
     } 
     data[i].name = formatName.join(' '); 
    } 
    } 

// $http.get("https://api.github.com/search/repositories?q=user:tulun").success(function (data) { 
// console.log(data); 
// }); 

// https://api.github.com/search/repositories?q=user:tulun 
// https://api.github.com/search/repositories?q=user:aipub 

答えて

0

あなたはこのプロジェクトを試すことができます

アクセストークンをセットアップする必要があります。

+1

ですか?それは他のユーザーのための適切な値を返すようです。情報を表示するために認証が必要なユーザーもいますか? – Tulun

+0

あなたは働くフィドルかplnkrを作成できますか? –

+0

ここに行きます:https://jsfiddle.net/o1fb31z6/ 私はJSをHTML部分に入れました(それについては申し訳ありません、それは作った:)) – Tulun