ebay 购物 API AngularJS 意外错误

ebay shopping API AngularJS unexpected error

angular.module('BeautyCare', ['ionic'])
 
 .config(function($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state('tabs', {
      url: "/tab",
      abstract: true,
      templateUrl: "templates/tabs.html"
    })
    .state('tabs.Store', {
      url: "/Store",
      views: {
        'Store-tab': {
          templateUrl: "templates/Store.html",
          controller: 'StoreTabCtrl'
        }
      }
    })
    
    .state('tabs.SalonGalary', {
      url: "/SalonGalary",
      views: {
        'SalonGalary-tab': {
          templateUrl: "templates/SalonGalary.html",
          controller :'SalonGalaryCtrl'
        }
      }
    })
    
    .state('tabs.Profile', {
      url: "/Profile",
      views: {
        'Profile-tab': {
          templateUrl: "templates/Profile.html"
        }
      }
    })

    .state('tabs.Alerts', {
      url: "/Alerts",
      views: {
        'Alerts-tab': {
          templateUrl: "templates/Alerts.html"
        }
      }
      });

   $urlRouterProvider.otherwise("/tab/Store");

});


.controller('StoreTabCtrl', function($scope,$http,$log) {
    var items =null;
    $log.debug('start debug');
    var url="http://open.api.ebay.com/shopping?GLOBAL-ID=EBAY-IN&QueryKeywords=Iphone&ResponseEncodingType=JSON";
    url+="&appid=API_ID&callback=JSON_CALLBACK._0";
    url+="&callname=FindPopularItems&version=713?callback=JSON_CALLBACK";
   $log.debug($http.jsonp(url)
            .success(function(data) {
            items=data;
            console.log(items);
            })
            .error(function(data) {
                //alert("ERROR");
            }));        
});
  <html >
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    
    <title>Beauty Care</title>
    <!-- MyBeauty , BeautyCare,BeautyEye,BeautyShop,BeautySalon !-->

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="js/app.js"></script>
    <script src="js/Service.js"></script>
    <script src="js/Controllers.js"></script>
   <!--  <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBLSOMXsw_sxOlRpyBj16g5iaewLHDpSes&libraries=places"></script>
 -->
  </head>

  <body ng-app="BeautyCare">
    
    <ion-nav-bar class="bar-positive">
      <ion-nav-back-button>
      </ion-nav-back-button>
    </ion-nav-bar>
             
    <ion-nav-view></ion-nav-view>


    <script id="templates/tabs.html" type="text/ng-template">
      <ion-tabs class="tabs-icon-top tabs-positive">

        <ion-tab title="" icon="ion-ios-cart" href="#/tab/Store">
          <ion-nav-view name="Store-tab"></ion-nav-view>
        </ion-tab>

        <ion-tab title="" icon="ion-navicon-round"  href="#/tab/SalonGalary">
          <ion-nav-view name="SalonGalary-tab"></ion-nav-view>
        </ion-tab>

        <ion-tab title="" icon="ion-android-person" ui-sref="tabs.Profile">
          <ion-nav-view name="Profile-tab"></ion-nav-view>
        </ion-tab>

        <ion-tab title="" icon="ion-ios-bell" ui-sref="tabs.Alerts">
          <ion-nav-view name="Alerts-tab"></ion-nav-view>
        </ion-tab>
      </ion-tabs>
    </script>

    <script id="templates/Store.html" type="text/ng-template">
      <ion-view view-title="BeautyCare Store" cache-view="false">
        <ion-content class="padding" >
        <ion-list>
      <ion-item class="item-icon-right" ng-repeat="item in items">
          <h1>{{item.TimeStamp }}</h1>
          <!--<p>{{ item.title}}</p> !-->
          <i class="icon ion-chevron-left icon-accessory"></i>
          <ion-option-button class="button-positive" ng-click="viewFriend(viewFriend(data.idfriends))">View Friend</ion-option-button>
          <ion-option-button class="button-assertive" ng-click="deleteFriend(remove(data.idfriends))">Delete</ion-option-button>
      </ion-item>
    </ion-list>
        </ion-content>
      </ion-view>
    </script>

    
    
    <script id="templates/SalonGalary.html" type="text/ng-template">
      <ion-view view-title="BeautyCare Salon Galary" cache-view="false">
        <ion-content class="padding">
         
        </ion-content>
      </ion-view>
    </script>

    
    <script id="templates/Profile.html" type="text/ng-template">
      <ion-view title="My Profile" cache-view="false">
        <ion-content>
         
        </ion-content>
      </ion-view>
    </script>

     <script id="templates/Alerts.html" type="text/ng-template">
      <ion-view view-title="My Alerts" cache-view="false">
        <ion-content class="padding">
          
        </ion-content>
      </ion-view>
    </script>


  </body>
</html>
  
    

</body>
</html>

我尝试使用 $http.get 但没有成功,代码显示意外错误。 我感谢任何帮助解决此问题或使用 $http.get 的解决方法。我尝试了不同的例子,但仍然没有解决问题。提前致谢

让我们仔细看看您正试图发送到 eBay 的 URL API:

http://open.api.ebay.com/shopping?GLOBAL-ID=EBAY-IN&QueryKeywords=Iphone&
  ResponseEncodingType=JSON&appid=Mawsem77f-2832-4be9-93d8-e257a245be3&
  callback=JSON_CALLBACK._0&callname=FindPopularItems&version=713?callback=JSON_CALLBACK

我算了三个问题:

  • version 参数的值无效:713?callback=JSON_CALLBACK。此参数似乎需要一个数值。请注意,URL 的这一部分已经在查询字符串中,因此此处的 ? 不会被解释为查询字符串的开头或参数分隔符。

  • 如果 URL 末尾的 callback=JSON_CALLBACK 应该是另一个 URL 参数名称和值,那么您指定了 callback 参数具有两个不同的值。您只需要指定一次该参数,您还需要决定使用哪个值。

  • 当您制作 JSONP request you need to specify the name of a function to wrap the returned JSON in. However, according to the eBay API documentation 时,您使用了错误的参数作为回调函数的名称。如果参数 callback 的值为 true,则响应将包含在对名为 _cb_FindPopularItems 的函数的调用中。此参数的其他值似乎被忽略了。您似乎想改用 callbackname 参数。因此,请尝试从您的 URL 中删除两个 callback 参数并添加 callbackname=JSON_CALLBACKcallbackname=JSON_CALLBACK._0(这里不清楚您打算使用哪个)。

    这也解释了语法错误:假定对 JSONP 请求的响应是可执行的 JavaScript 但您得到的响应实际上是一些 JSON 数据。

我还没有对此进行测试,但我希望下面的 URL(为了便于阅读而换行)能够工作。您可能需要在回调名称中添加 ._0 后缀:

http://open.api.ebay.com/shopping?GLOBAL-ID=EBAY-IN&QueryKeywords=Iphone&
  ResponseEncodingType=JSON&appid=Mawsem77f-2832-4be9-93d8-e257a245be3&
  callbackname=JSON_CALLBACK&callname=FindPopularItems&version=713

最后,请考虑更改您的 eBay 应用 ID。您现在已将它发布在 public 互联网上,任何查看此问题的人现在都可以使用它。我以前从未使用过 eBay 及其 API,所以我会留给您来弄清楚如何执行此操作。