How to get access tokens of users in external network?

允我心安 提交于 2019-12-24 14:19:27

问题


I have a admin account, first I got access tokens for each network the admin account is a member. second I used the user_id and consumer_key parameters to generate tokens on behalf of other users. But when I try to get access token of user in external network,I got a 401 error. There is no problem to get access token of user in main network.I want to know is there any way to get access tokens of users in external networks.


回答1:


The network parameter is the key in the puzzle when invoking the login method. Due to some cross domain restrictions, the SDK creates a hidden iframe on the page to serve as a proxy bridge to get a token for the external network.

yam.platform.login({ network: '{your-permalink-goes-here}' }, function (data) {

    console.log('login-status: ',data)
    if(data.status ==='connected')
        yam.platform.request({
            url: "oauth/tokens.json"     
            , method: "GET"
            , success: function (tokens) { console.log('user-tokens:',tokens); }
            , error: function (err) { alert("There was an error with the request."); }
        });
})

The obtained token can be then manually set for further requests whenever the page is reloaded, avoiding the login window to show up again.

yam.platform.setAuthToken('{the-token-goes-here}'))


来源:https://stackoverflow.com/questions/25903804/how-to-get-access-tokens-of-users-in-external-network

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!