title: Yammer REST API: How to get access tokens for external networks?
body: <p>I'm working on an ASP.NET web application that reads data from Yammer. I've successfully acomplished authentication and getting messages from the "home" network.</p>
  
  <p>Now I want to switch to another network and get messages from it. I've read all the <a href="https://developer.yammer.com/introduction/" rel="nofollow">documentation</a> and specifically the <a href="https://developer.yammer.com/restapi/#rest-networks" rel="nofollow">Networks</a> section which states the following:</p>
  
  <blockquote>
    <p>Facilitates switching a user between different Yammer networks. All
    Yammer web requests contain a network permalink in the URL
    (<a href="https://www.yammer.com/network_permalink/resource_path" rel="nofollow">https://www.yammer.com/network_permalink/resource_path</a>) to denote the
    network context. API requests use a different OAuth token for each
    user/network combination.</p>
    
    <p>Endpoint: Returns a list of networks to which the current user has
    access. Supports included_suspended parameter.</p>
    
    <p><code>GET https://www.yammer.com/api/v1/networks/current.json</code></p>
  </blockquote>
  
  <p>Ok, so I need to get the corresponding token for the user/network combination. Perfect.
  I do a <code>GET</code> request to that <code>networks/current.json</code> endpoint and I get all the networks the current user has access to. Great. Now, where are the tokens? They aren't in the json response.</p>
  
  <p>So... </p>
  
  <ul>
  <li>How do I get messages from external networks using the Yammer REST
  API via server-side code? </li>
  <li>How do I get the tokens for the external
  networks?</li>
  </ul>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Following Brian's suggestion:</p>
  
  <ol>
  <li>I do a <code>GET https://www.yammer.com/api/v1/oauth/tokens.json</code> passing the current token in the authentication header (<code>Bearer: xxxxxxxxx</code>)</li>
  <li>This returns the 2 networks the user I'm using is in. The home and the external. One thing I noticed is that the <code>user_id</code> is different for each network. I don't know if that's another user or if the same user has a different <code>user_id</code> for each network.</li>
  <li>Now I want to get messages from the other network so I do a </li>
  </ol>
  
  <p><code>GET https://www.yammer.com/api/v1/messages.json</code></p>
  
  <p>but now using the token for the external network I got from the <code>tokens.json</code> endpoint.  But I get the following response:</p>
  
  <pre><code>{
    "response":
       {
        "stat":"fail",
        "code":17,
        "message":"Attempt to access a protected resource failed."
       }
   }
  </code></pre>
  
  <p>And again, according to the doc that endpoint is for impersonation and restricted to verified admin users in paid Yammer networks.</p>
  
  <p>I have no clue really.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>The process described in the above update works for the user (me) that created the Yammer App. I'm using. Other users can't get messages from external networks unless I'm in that network. So it seems like they are using my tokens, but that's impossible unless there's a bug in the API.</p>