Buddy.loginUser code snippet doesn't work

Solved!
Posted in General by remco koffijberg Sat Sep 10 2016 09:56:58 GMT+0000 (UTC)·14·Viewed 1,113 times

Hi all, I'm just starting with Buddy, it looks great. I added jquery.min.js, buddy.js, and the Buddy.init command. I did add the snippet Buddy.post without a problem. It throws an error (since i'm not logged in) which indicates everything works fine. I also see "device registration complete" in the console. If i paste the Buddy.loginUser code snippet into the js file i get immediate errors such as: - expected ')' and instead saw '{' - missing semicolon - expected an identifier and instead saw '@' etc. I'm working in Monaca Cloud (= Phonegap), working in JS. Any ideas? Am i missing something?
remco koffijberg
Sep 10, 2016

I found out that i can use:

Buddy.loginUser('test', 'password', [callback]);

that is, as i delete [callback]. I don't know how to implement 'callback'.

Now i get: AuthAccesTokenInvalid

I'm not sure what it is, since i copied the init key directly from the dashboard.

remco koffijberg
Sep 10, 2016

And then i found my error message, and the explanation is...

An Access Token either has expired, or has been revoked. Additionally, this error will result if a user Access Token is used after it has been used to log out the user:

I still don't know what exactly the access token is, but i assume now it is from the user (not from the init). Also i don't know what to do about it...

Bradley Serbus
Sep 11, 2016

HI Remco,

The callbacks in the JavaScript SDK are implemented like this: function (error, result) { }. Before calling loginUser(), you need to call Buddy.init() with your app's ID and key. Those can be retrieved from the Settings -> Security section of https://portal.buddy.com, after you create and select your app there.

Access tokens are how we authenticate/authorize our service. See http://docs.buddy.com/docs/service-authentication for more details. Our SDKs hide those details though, so after calling Buddy.init(), all you should need to do is call Buddy.loginUser().

If you still have problems please let me know.

Thanks for using Buddy!
Brad

remco koffijberg
Sep 11, 2016

Thank you for your reply!

my error: " 401.AuthAccessTokenInvalid 260" is that for the wrong code in the app ID / key in the Init()?

Bradley Serbus
Sep 12, 2016

Hi Remco,

You should only get that error upon calling login or create user. I tested login and am able to log in successfully. Can you send along a copy/paste of your code to [email protected] so I can take a look?

Thanks,
Brad

remco koffijberg
Sep 12, 2016

That is wonderful support!

I will do this.

remco koffijberg
Sep 19, 2016

Hi Bradley

Are you still receiving my email?

tx
Remco

Bradley Serbus
Sep 19, 2016

Hi Remco,
I've been sending emails from [email protected] Can you double-check your inbox? I sent you a pull request for the JavaScript SDK that may solve your issue. You can go to our GitHub repo at https://github.com/BuddyPlatform/Buddy-JS-SDK/pulls and see if that helps.
Thanks,
Brad

remco koffijberg
Sep 19, 2016

Hi Brad

Yes i found a new version (many thanks!). I now have this error:

Uncaught SyntaxError: Unexpected end of JSON input www/index.html: 1

I look better to me (-; but i don't know how to solve this.

Bradley Serbus
Sep 19, 2016

Hi Remco,

I'll follow up from my personal work account.

Thanks,
Brad

remco koffijberg
Sep 20, 2016

Hi Brad,
I didn't know i posted to your personal account, sorry for that. But anyways, here it is:

function blob(){

Buddy.createUser({
username: 'test',
password: 'password',
firstName: 'Test',
lastName: 'User',
email: '[email protected]',
dob: '4/23/1980'
});
}

Bradley Serbus
Sep 20, 2016

Hi Remco,

Silly typo in the pull request, I've fixed it. Please give it another try.

Thanks,
Brad

remco koffijberg
Sep 20, 2016

It works!!!!!!!!

thanks Brad!

Bradley Serbus
Sep 20, 2016

Superb! Thanks for using Buddy!

Brad


Bradley Serbus marked this as solved
Markdown is allowed