@FlyToDream

Как подключить Ionic Framework и woocommerce api?

Такая проблема:
Создаю приложение под Ionic + WC-API.
При попытке получить доступ к товарам пишет не валидый ключ. Создал ключ в Woocommerce Админке. На просторах интернета нашел, что нужна еще аутентификация.
Вроде есть рабочей код, но вставляю код и не работает (state просто не открывается):
stackoverflow.com/questions/35889338/call-woocommerce-2-1-rest-apt-in-ionic-framework-using-ouath1-a
santoshshinde2012.blogspot.ru/2016/03/woocommerce-rest-api-with-ionic.html#comment-form

Ключи поставил свои.
Эти библиотеки скачал и подключил в index.html:
hmac-sha1.js
enc-base64.js
oauth-1.0a.js
oauth-signature.js

angular.module(myapp.restservices', [])
.service("woocommerce",['$q','$http','errorHandler','$ionicLoading',
               function($q,$http,errorHandler,$ionicLoading){
                var self=this;

    //Request Url and method
               var request = {
                       url: 'http://www.example.com/wc-api/v3/products',
                       method: 'GET' 
                }; 

   //OAuth Protocol authentication parameters
   var oauth = new OAuth({
                      consumer: {
        //Consumer Public Key
                                         public: 'ck_50xxxxxxxx',
        //Consumer Secrete Key
                                          secret: 'cs_b5xxxxx'
                        },
          //oauth1.0a protocol signature method
                      signature_method: 'HMAC-SHA1'
               });
  
 //Service Function to get products

            this.products=function(){
   $ionicLoading.show({
                                 template: '<ion-spinner class="light"></ion-spinner>'
                      });

  //OAuth Parameters to call woocommerce api      
 var oauth_data = {
             oauth_consumer_key: oauth.consumer.public,
             oauth_nonce: oauth.getNonce(),
             oauth_signature_method: oauth.signature_method,
             oauth_timestamp: oauth.getTimeStamp()
           };

          //Oauth signature
          oauth_data.oauth_signature =  oauthSignature.generate(request.method,request.url,
                                                       oauth_data,oauth.consumer.secret );
          console.log("Params : "+ JSON.stringify(oauth_data));

          var deff=$q.defer();

           $http({
                      method:request.method,
                      url:request.url,
                      headers: {
                                "Content-Type":"application/JSON",
                        },
            params: oauth_data
            }).then(function(objS){
      $ionicLoading.hide();
                alert('Success :-    '+JSON.stringify(objS));
            },function(objE){
     $ionicLoading.hide();
                alert('error:-    '+JSON.stringify(objE));
                errorHandler.serverErrorhandler(objE);
                deff.reject("server Error");
            });
            return deff.promise;
        };
    }])

    .service('errorHandler',['$q',function($q){
        this.serverErrorhandler=function(error){
            alert("ERROR ::"+JSON.stringify(error));
            console.log("ERROR ::"+JSON.stringify(error));
        };
     }
])


angular.module(myapp.categorycontrollers, [])


.controller('MainCtrl', function($scope,woocommerce) {


        //Method to get all Products
          $scope.getAllProducts = function(){
                woocommerce.products().then(function(objS){
                 },function(err){
                });
          }


         //calling to function
          $scope.getAllProducts();
 }


Но все равно не работает. Как получить список продуктов sitename.ru/wc-api/v3/products и пройти эту аутентификацию. Приложение дебажу в VisualStudio 2015 (локальный сервер с выходом в интернет - сеть есть). Когда делал вывод постов через WordPress API - все отлично работает, а с WC такая проблема.
  • Вопрос задан
  • 556 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы