Authenticating in javascript examples?

37 views
Skip to first unread message

Joost

unread,
Jan 11, 2013, 7:00:51 AM1/11/13
to leaguevine...@googlegroups.com
Hi,

I'm having difficulties with authenticating my javascript web app to the Leaguevine API. I tried looking at the Ultistat app for guidance, but this is a bit to much hardcore for me. Are there some more straight forward examples of authenticating  to the Leaguevine API with javascript around?

Most obliged,
Joost

Mark Liu

unread,
Jan 16, 2013, 10:31:35 PM1/16/13
to leaguevine...@googlegroups.com
Hey Joost,

For authenticating the user and retrieving an access token you need to construct a URL with your client app's details and direct your user to that URL. After they authenticate successfully, they will be redirected back to your site and the access token will be in the URL. You have probably seen this already, but in case you haven't, I'm referring to Method 1 in our authentication docs.

Once you have the access token, you'll need to make ajax calls to our API based on our documentation. What we do for parts of leaguevine.com is we extend jQuery's ajax call a bit in order to be able to pass in arbitrary API parameters in addition to the resource name. Here's the script we use to do this. It expects that jQuery is imported and it has access to a variable called 'access_token'. This then allows us to make calls such as this:

            $.api({
                type: 'GET',
                resource: 'players',
                first_name: 'first_name',
                last_name: 'last_name',
                nickname: 'nickname',
                success: function(data){
                    // do something interesting
                },
            });

I hope that helps!

Mark
Reply all
Reply to author
Forward
0 new messages