0

I have a very basic question, I have the following code, I basically just trying to login to dailymotion.

window.dmAsyncInit = function()
{
    DM.init({apiKey: 'MyAppID', status: true, cookie: true});
    console.log('sdk loaded');
};

DM.Event.subscribe('auth.login', function(response)
        {
            // do something with response
    if (response.status == 'connected')
        {
        console.log('connected');
        testAPI();
        }
    else
        {
        DM.login(function(response)
                {
                    if (response.session)
                    {
                        if (response.session.scope)
                        {
                            // user is logged in and granted some permissions.
                            // perms is a comma separated list of granted permissions
                        }
                        else
                        {
                            // user is logged in, but did not grant any permissions
                        }
                    }
                    else
                    {
                        // user is not logged in
                    }
                }, {scope: 'read write'});

        }


        });
(function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol + '//api.dmcdn.net/all.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(e, s);
}());


function testAPI() {
    DM.api('/user/rs', {fields: "screenname"}, function(response)
            {
                alert('Name is ' + response.screename);
            });
}

I have subscribed to auth.login, but I am not sure how I fire up this event. I want to create a login button for dailymotion and bind this event to the button. How can I do this?

Tilly
  • 427
  • 1
  • 4
  • 10
kosta
  • 4,302
  • 10
  • 50
  • 104

1 Answers1

0

You have to create a button which will fire a login function on the "onclick" event.

How to login is described at http://www.dailymotion.com/doc/api/sdk-javascript.html#sdk-javascript-method-login

Basically, you call the DM.login function, which will prompt the user to login (a pop-up window will appear for the user to log in).

Tilly
  • 427
  • 1
  • 4
  • 10