如何将Angular $ http GET数据发送到GitHUB API [重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我成功地从GitHub撤回了给定回购的所有问题,但是,现在我正在尝试利用下面链接中讨论的'since'参数来限制结果并且我很难过。根据Mozilla的说法,甚至没有发送参数。

GitHub文件:https://developer.github.com/v3/issues/

function getIssues(callback) {
    var owner = $('#owner').val();
    var repo = $('#repo').val();
    $scope.owner = owner;
    $scope.repo = repo;

    var urlBase = 'https://api.github.com/';
    var urlUser   = urlBase + 'users/' + owner;
    var urlUserRepos  = urlUser + '/repos';

    var urlRepoIssues = urlBase + 'repos/' + owner + '/' + repo + '/issues';

    var ownerInput = angular.element(document.querySelector('#owner'));
    var repoInput = angular.element(document.querySelector('#repo'));
    var sinceInput = angular.element(document.querySelector('#since'));
    var errorFeedback = angular.element(document.querySelector('#errorFeedback'));
    var sinceDate = sinceInput.val();
    var tempDate = '2018-09-17T23:27:31Z';

    $http({
        method: 'GET',
        url: urlRepoIssues,
        headers: {'Content-Type': 'application/json'},
        data: { 'since': tempDate }
    }).then(
        //Success
        function(response) {
            ownerInput.addClass('is-valid').removeClass('is-invalid');
            repoInput.addClass('is-valid').removeClass('is-invalid');
            errorFeedback.html('');

            var data = response.data;
            callback(data);
        },
        //Fail
        function(response) {
            ownerInput.addClass('is-invalid').removeClass('is-valid');
            repoInput.addClass('is-invalid').removeClass('is-valid');
            errorFeedback.html('The Owner or Repo is incorrect.');

            var data = [];
            callback(data);
        }
    );
};
angularjs api github parameters get
1个回答
0
投票

数据不适用于GET,只有PUT,但params可以与GET一起使用。因此,以下工作:

$http({
  method: 'GET',
  url: urlRepoIssues,
  params: { 'since': sinceDate }
}) 
.
.
.

另请注意日期应如何格式化:

var sinceDate = new Date(sinceInput.val()).toISOString();
© www.soinside.com 2019 - 2024. All rights reserved.