Firebase 将Instragram API中的照片添加到AngularFire中的同步阵列

Firebase 将Instragram API中的照片添加到AngularFire中的同步阵列,firebase,angularfire,instagram-api,Firebase,Angularfire,Instagram Api,我使用Instagram API和Angular构建了一个简单的Instagram应用程序 现在我想将用户搜索(即Instagram服务器对输入的每个标签的响应)永久存储到Firebase 我让Instagram API调用正常工作,并将其保存为$scope.instadata,但如何使用$add()将$scope.instadata添加到Firebase 我犯了个错误: angular.js:11500错误:Firebase.set失败:第一个参数包含函数 这是我第一次在这里问问题,使用API

我使用Instagram API和Angular构建了一个简单的Instagram应用程序

现在我想将用户搜索(即Instagram服务器对输入的每个标签的响应)永久存储到Firebase

我让Instagram API调用正常工作,并将其保存为
$scope.instadata
,但如何使用
$add()
$scope.instadata
添加到Firebase

我犯了个错误:

angular.js:11500错误:Firebase.set失败:第一个参数包含函数


这是我第一次在这里问问题,使用API、Angular和Firebase!我希望没问题

您从jsonp收到的
数据
包含许多您可能不需要添加到firebase的内容。试着从中分离出你所需要的(在你的例子中可能是
数据。数据
)它工作了!!!我通过了$scope.instadata.data.data--非常感谢@RonHarlev!祝你周末愉快:)
var app = angular.module('InstagramApp', ['firebase']);

app.controller('MainController', function ($scope, $http, $firebaseArray) {

  // search posts based on hashtag
  function getHash() {
    var base = 'https://api.instagram.com/v1/tags/'
    var service = document.getElementById('hashtag').value
    var apiKey = '####'
    var callback = 'JSON_CALLBACK'
    var url = base + service + '/media/recent?access_token=' + apiKey + '&callback=' + callback

    // use jsonp method to prevent CORS error
    $http.jsonp(url).then(function(data) {

        $scope.instadata = data
        console.log("returned json object: ")
        console.log($scope.instadata)

        // set up firebase reference
        var ref = new Firebase('https://myapp.firebaseio.com/fbdata')

        // create a synchronized array 
        $scope.fbdata = $firebaseArray(ref)

        // add new items to the array RETURNS ERROR
        $scope.fbdata.$add($scope.instadata).then(
            function(p){
            console.log(p.key())
            console.log($scope.instadata)
            }, 
            function(err){
            console.log("The expected Firebase action failed to occur this was your error: " + err)
            })  
        }

     })
  }
  document.getElementById('hashtag').addEventListener('click', getHash, false) 
})