Start a new topic

Failed to retrieve the document using Angularjs

Hi everyone,


Why I get this message?

Kinvey: Failed to retrieve the document. Object {name: "NoActiveUser", description: "You need to be logged in to execute this request.", debug: "Try creating a user using Kinvey.User.signup, or login an existing user using Kinvey.User.login."}

My code:

access.js

var app = angular.module('myApp', ['kinvey']);
      app.run(function($kinvey) {
            $kinvey.init({
            appKey : 'myKey',
            appSecret : 'mySecret'
        })
      });

My controller (ctrller.js)

app.controller('myController', ['$scope', '$kinvey', function($scope, $kinvey) {

     $scope.save = function() {

      var promise = Kinvey.DataStore.get('My device name on kinvey','the id number');
      promise.then(function(response) {
          console.log(response);

    });    

    }   

  }]);

Thank you.


appSecret cannot be used to do anything in Kinvey other than create users. 


You can create end users for your app over here and they will be able to query your collections without issue. http://devcenter.kinvey.com/angular/guides/users#signup


Thanks,

Hi Damien,

the point is: I´m just trying read some data from kinvey, and I got this message.

I didn´t try do something like singup, sigin, or something else.


Thank you so much.

Samyr,


My apologies that I wasn't clear about this in my earlier response, Kinvey requires an active user at all times.   Our collections are made using Access Control Lists which dictate who can see / interact with different objects / collections; therefore, our REST api requires a logged in user for any call.  The user that you are trying to use (app secret) does not have permission to query anything in Kinvey.  The appSecret user can only create new users. 


You can read more about how users interact with the Rest API in our rest API guide:  http://devcenter.kinvey.com/rest/guides/users#usersessions  The link above to sign up a user would likely be more useful to your specific use case since it goes over the backbone implementation of signing up a user.


Thanks,


Whoops, re-read and realized you were using Angular, my apologies, I reflected the link in my earlier post to reflect this


I got it Damien,

could you send me a simple example, please? 

Tku so much.

Samyr,


The guide I sent you: http://devcenter.kinvey.com/angular/guides/users#signup  Goes over how to sign up (with source code examples) and the guide over here:  http://devcenter.kinvey.com/angular/guides/datastore#Fetching  Will show you how to get it back.


Thanks,


1 person likes this

Thank you Damien, I got and now it´s working.


But now I have another point. Could you help me?

I got this message: 


Kinvey: A Kinvey.Error was thrown. Kinvey.getActiveUser can only be called after the promise returned by Kinvey.init fulfills or rejects.


I know there I should add a callback to the kinvey.init function.

But I don´t know how can I do that. 

Could you help me?

Tks again.


This is my code:

var app = angular.module('myApp', ['kinvey']);

      app.run(function($kinvey) {

       $kinvey.init({ 

             appKey : 'my key',

             appSecret : 'my secret'

        }).then(function() {

        var user = $kinvey.getActiveUser();

        if(null == user) {

             var promise = $kinvey.User.login({

             username : 'teste',

             password : 'teste'

        });

        promise.then(function(user) { 

             console.log('User in');

        }, function(err) {

             console.log(err);

        });

      }

    ...

Tku Damien, I got it and now it´s working.

But I have another point. Could you help me?

I got this message:

Kinvey: A Kinvey.Error was thrown. Kinvey.getActiveUser can only be called after the promise returned by Kinvey.init fulfills or rejects.

I know there I should add a callback to the kinvey.init function.

But I don´t know how can I do that.

Could you help me?

My code:

var app = angular.module('myApp', ['kinvey']);

      app.run(function($kinvey) {

        // Initialize Kinvey for use in your app.

 $kinvey.init({

  appKey : 'my key',

  appSecret : 'my secret'

        }).then(function() {

   var user = $kinvey.getActiveUser();

   if(null == user) {

          var promise = $kinvey.User.login({

              username : 'teste',

              password : 'teste'

          });

          promise.then(function(user) {

            console.log('User in');

          }, function(err) {

             console.log(err);

          });

        }

        });

      });

Login or Signup to post a comment