我有一个非常基本的问题,我有以下代码,我基本上只是尝试登录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 创建一个登录按钮,并将此事件绑定到该按钮。我该怎么做?
您必须创建一个按钮,该按钮将在"onclick"事件上触发登录功能。
如何登录在 http://www.dailymotion.com/doc/api/sdk-javascript.html#sdk-javascript-method-login
基本上,您调用 DM.login 函数,该函数将提示用户登录(将出现一个弹出窗口供用户登录)。