我可以在控制台中打印access_token和result数组。但是,当我尝试将数据附加到new Option时,它不起作用。
初始化
window.pAsyncInit = function() {
PDK.init({
appId: "client_id",
cookie: false
});
};
(function(d, s, id){
var js, pjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//assets.pinterest.com/sdk/sdk.js";
pjs.parentNode.insertBefore(js, pjs);
}(document, 'script', 'pinterest-jssdk'));身份验证脚本
function login() {
//login
PDK.login({ scope : 'read_relationships,read_public,write_public' }, function(response){
if (!response || response.error) {
// alert('Error occurred');
} else {
PDK.request('/v1/me/', function (result) {
if (!result || result.error) {
//alert('Error occurred');
} else {
var access_token = PDK.getSession().accessToken;
console.log(access_token); // works and prints well
console.log(result); // works and prints well
//option works but empty
pages= new Option(result.data.first_name,access_token).dataset['id'] =result.data.id;
//PDK.logout();
}});
}
});
};发布于 2017-10-05 05:29:18
这是有效的答案。
function login() {
//login
PDK.login({ scope : 'read_relationships,read_public,write_public' }, function(response){
if (!response || response.error) {
// alert('Error occurred');
} else {
PDK.request('/v1/me/', function (result) {
if (!result || result.error) {
//alert('Error occurred');
} else {
var text = result.data.first_name;
var value = PDK.getSession().accessToken;
var additionalData = result.data.id
//Create the option
var option = new Option(text, value);
pages.add(option);
//create the data-id attribute, add it to the option
var attribute = document.createAttribute("data-id");
option.setAttributeNode(attribute);
//Assign the respective data to the data-id attribute
option.dataset['id'] = additionalData;
//PDK.logout();
}});
}
});
};https://stackoverflow.com/questions/46554631
复制相似问题