How do you get a user's id from a Magento REST

2019-05-07 06:28发布

问题:

Following these instructions, it's easy to see that Magento is associating the OAuth tokens with a user id after they're granted. Is there a way to programmatically recover the user id, given the OAuth token?

回答1:

If helps, you can do it like this:

// Should be a collection of one element (or zero if nothing found)
$tokens = Mage::getModel('oauth/token')->getCollection()->addFilterById($tokenId);
foreach ($tokens as $token) {
    echo $token->getCustomerId();
}