none
I keep Getting 401 unauthorized from Yammer REST Endpoint, even though I have provided the right access token RRS feed

  • Question

  • Hi,

    Below is my code snippet, looks fairly simple but the Yammer Service always returns 401 unauthorised.

                string endPoint = "https://www.yammer.com/api/v1/messages/following.json";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endPoint);
                request.Method = "GET";
                request.Host = "www.yammer.com";
                request.KeepAlive = true;
                request.Credentials = System.Net.CredentialCache.DefaultCredentials;
                request.ContentType ="application/json; charset=utf-8"; 
                request.Headers.Add("Authorization","Bearer XXXXXXX");
                 wResp = (HttpWebResponse)request.GetResponse();
                 StreamReader reader = new StreamReader(wResp.GetResponseStream());
                return reader.ReadToEnd().ToString();

    Kindly help to point out the issue, or if any workaround exists kindly tell me that too!!

    Regards,

    Dinesh

    Tuesday, July 22, 2014 5:53 AM

Answers

  • Hi,

    The Yammer API requires the OAuth data to be in the header. If you look at their example for Getting Data, you'll see the request looks like.

    GET /api/v1/messages/favorites_of/1234 HTTP/1.1

    HOST: www.yammer.com

    Authorization: OAuth  oauth_consumer_key="KsTROcNF1Fx3e1PwA",oauth_token="vlVH7A7DOm9wXuHdv58A",oauth_signature_method="PLAINTEXT",oauth_timestamp="1297383841092",oauth_nonce="1047685618",oauth_verifier="E4F8",oauth_signature="yPsEvDnNPIA8xGCFLvMJ73K0DD9ivMpATJeFOSo%26fSFh9UPkHQ6oRwK5OTne33ltnSnbQ9XrAhA72heg"

    The OAuth data is in the Authorization header and not in the URL. The only time you have any OAuth data in the URL is when you do the authorize.

    For more information, please try to refer to this similar thread:
    http://stackoverflow.com/questions/18533355/bearer-token-in-the-oauth-authorization-request-header-for-rest-api-post-call .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, July 23, 2014 5:37 AM
    Moderator