-->

How to get access tokens of users in external netw

2019-08-14 15:08发布

问题:

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}'))


标签: yammer