MailChimp API http请求

时间:2017-03-14 12:52:56

标签: angularjs curl mailchimp

我希望在我的网络应用中集成mailchimp api。

文档在这里: http://developer.mailchimp.com/documentation/mailchimp/guides/get-started-with-mailchimp-api-3/#before-you-start

如何在Http请求中翻译Curl? (Angular JS)

curl --request GET \
--url 'https://<dc>.api.mailchimp.com/3.0/' \
--user 'anystring:<your_apikey>'

这&#34; - 用户&#34;是URL或标题中的字符串?

抱歉我的英语不好。谢谢

1 个答案:

答案 0 :(得分:0)

在您的控制器中,您将注入$ http服务并将其命名为

myApp.controller('GreetingController', ['$scope', '$http', function($scope, $http) {
  //this key comes from Mail Chimp
  $scope.myApiKey = "2039rslkdjf=34$#34098-us15";
  $scope.endOfKey = "us15";
$http.get({
      method: 'GET',
      url: 'https://' + $scope.endOfKey + '.api.mailchimp.com/3.0/',
      authorization: 'anystring ' + $scope.myApiKey
    })
    .then((response) => {
      //do something once it comes back
     })
    .error((error) => {
      //do something in case there's an error
     })
    .finally(() => {
      //do something after either success or error
     })
}]);