0

我有一个非常基本的问题,我有以下代码,我基本上只是想登录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);
            });
}

我已订阅 auth.login,但我不确定如何启动此活动。我想为 dailymotion 创建一个登录按钮并将此事件绑定到该按钮。我怎样才能做到这一点?

4

1 回答 1

0

您必须创建一个按钮,该按钮将在“onclick”事件上触发登录功能。

http://www.dailymotion.com/doc/api/sdk-javascript.html#sdk-javascript-method-login描述了如何登录

基本上,你调用 DM.login 函数,它会提示用户登录(会出现一个弹出窗口让用户登录)。

于 2014-05-09T14:46:11.873 回答