首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Pinterest Javascript SDK获取first_name?

如何使用Pinterest Javascript SDK获取first_name?
EN

Stack Overflow用户
提问于 2017-10-04 06:55:20
回答 1查看 160关注 0票数 1

我可以在控制台中打印access_tokenresult数组。但是,当我尝试将数据附加到new Option时,它不起作用。

初始化

代码语言:javascript
复制
   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'));

身份验证脚本

代码语言:javascript
复制
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();
}});
}

});
};
EN

回答 1

Stack Overflow用户

发布于 2017-10-05 05:29:18

这是有效的答案。

代码语言:javascript
复制
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();
}});
}

});
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46554631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档