Search Posts

Category: api

Getting Access-Control-Allow-Headers in preflight error

I have created angular js app in which I have integrate twitch api , the api is return $http({ url: “https://api.twitch.tv/kraken/streams”, method: “GET”, params: { channel: channel, limit: 1 }, headers: { “Client-Id”: “XXXXXXXXXXXXXXX” } }) the problem is when I reload the page the api is working but when my state changes without page reload I am getting cross origin error from this api. the error is Failed to load https://api.twitch.tv/kraken/streams?channel=eliazOne&limit=1: Request header field […]

Twitter Api return error 215 – Bad Authentication data

I’m accessing Twitter Search api into my Angular application getting following error. Implemented this change into https. Still getting same error {“errors”:[{“code”:215,”message”:”Bad Authentication data.”}]} twitter-service.js angular.module(‘TwitterServices’, [], function ($provide) { $provide.factory(‘$twitter’, function ($http, $log) { var consumerKey = encodeURIComponent(‘<consumerKey from twitter api>’); var consumerSecret = encodeURIComponent(‘<consumerSecret from twitter api>’); var credentials = Base64.encode(consumerKey + ‘:’ + consumerSecret); var twitterOauthEndpoint = $http.post( ‘https://api.twitter.com/oauth2/token’ , “grant_type=client_credentials” , { headers: { ‘Authorization’: ‘Basic ‘ + credentials, ‘Content-Type’: ‘application/x-www-form-urlencoded;charset=UTF-8’, […]

Angularjs Google Map API Integration

I’m trying to add a google map in angular JS… and have been struggling. I didn’t want to use one of the angular dependencies, but simulate the ‘async defer’ on the Google JS API site. I’m pretty new to Angularjs but get the concept of keeping things assigned to the controllers scope. Pretty sure it’s just something dumb, but not sure what… any help would be awesome 🙂 (function () { ‘use strict’; app.controller(‘travelCtrl’, [‘$scope’, […]

API to get a list of hotels with prices?

I am working on a project that requires me to make a mock hotel application. In doing so, I am in need of an api that gives me results for hotels in specified area (preferably by latitude and longitude), and gives me the results with images/ prices. I was using the google api, but that does not return prices. I am also using angular 4, if that makes a difference. Source: AngularJS

Angularjs display dynamic ID and info of particular User in $scope when login with Service and API to fetch in MySQL

I had this problem for AngularJS UI. I created a service to fetch a get method api /member/item/ + id, where my parameter id is the specified userID in my database table. I already setup a controller but I keep getting an error. Somehow I manage to get the ID of the user when I declare the value as 1. But I tried to make it dynamic it gives me error. Controller app.controller(‘mainCtrl’, function($scope, $window, […]

AngularJS Router: redirect to different view

I am making my first AngularJS App followed by this tutorial: https://www.toptal.com/angular-js/a-step-by-step-guide-to-your-first-angularjs-app The Github repository for my App is https://github.com/HillenLin/myFirstAngularProject/tree/master/app The problem is in my App when I direct to view 1, it works fine. It can load the HTML file with the information of all the drivers. However, when I click one specific driver, it can’t load the HTML page for the particular driver. How can I redirect to the HTML page of the […]

Angular CRUD to and from API

I am trying to build a system that you upload photos add photos to array, save photos. When you save photo it posts to a API, also the Array is per populated with the current images saved to the API on last visit. So User uploads photos and sees a preview (Working) Click add and it adds the preview image to the array (NOT WORKING FULLY) Save updated array and post to API. (Working but […]

Looping through Angular API calls

I have a list of items and I want to pass the selected items to the API and check if that item exists or not. $scope.submitButton = function() { for (var i=0; i < $scope.selectedItems.length; i++) { console.log($scope.selectedItems[i]); // item2 myService.checkItem($scope.selectedItems[i]) .success(data, status, header, config) { var myData = data; console.log(myData); }) } } When I select item2 and click the button, I only want the service to return data for item2 but it returns […]

400 Bad Request during magento 2 REST API Call

When using $http.get in angular, I have a problem: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource….. $http({ method: ‘GET’, url: ‘https://<magento_host>/rest/default/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=status&searchCriteria[filter_groups][0][filters][0][value]=processing,pending&searchCriteria[filter_groups][0][filters][0][condition_type]=in’, headers : { ‘Authorization’: ‘Bearer xxxxxxxxxxxxxxx’ } }).success(function (data) { }).error(function (data) { }); To avoid cross origin issue, I set below method in .htaccess file in Apache server. Header always set Access-Control-Allow-Origin “*” Header always set Access-Control-Allow-Methods “POST, GET, OPTIONS, PUT, DELETE” Header always set Access-Control-Allow-Headers: Authorization In […]

What is ‘API first architecture’ in modern web application

I try to understand the API first architecture to apply on web application, and found some info here, Advantages of a separate REST backend API? Below I attach an example for better answer of the questions. I start using Angular.js for front-end. Node.js, Express.js for server. folder structure |– server.js |– app |– models |– views |– index.html |– about.html |– contact.html |– controllers |– app.js |– node-modules app folder is a MVC structure for […]

Next Page »