具有授权承载者访问权限的Yammer REST API返回401 UnAuthorized

时间:2015-02-24 18:24:28

标签: c# authorization c#-5.0 yammer http-status-code-401

我正在尝试使用Yammer REST API来获取消息。获取OAuth令牌的过程的第一部分是成功的。当我获得401 UnAuthorized时,我在检索消息时传递oAuth令牌的方式出错了。

    //Create the HttpClient to the Yammer Access Token
HttpClient _client = new HttpClient();
            string query = string.Format("https://www.yammer.com/microsoft.com/dialog/oauth?client_id=rhIwJiPokWcaUZAR2VpgZg&redirect_uri=http://www.msn.com", queryToken);

            HttpResponseMessage yammerAuthTokenResponse = _client.GetAsync(query, HttpCompletionOption.ResponseHeadersRead).Result;

//if response is successful, capture the Yammer token
 if (yammerAuthTokenResponse.IsSuccessStatusCode)
{
 string HTMLYammerAuthCode =      
 yammerAuthTokenResponse.Content.ReadAsStringAsync().Result;
 strYammerAuthToken = GetYammerAuthToken(HTMLYammerAuthCode, strYammerAuthToken);
 Console.WriteLine(strYammerAuthToken);
}

//I get the YammerAuthToen and store it in strYammerAuthToken 
//I then try to get messages using this token

string queryReadMessages = "https://www.yammer.com/api/v1/messages/my_feed.json";
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", strYammerAuthToken);

HttpResponseMessage yammerAuthTokenResponseReadMessages = _client.GetAsync(queryReadMessages).Result;

这会产生401 UnAuthorized错误

1 个答案:

答案 0 :(得分:1)

更改

  

string queryReadMessages =   " https://www.yammer.com/api/v1/messages/my_feed.json&#34 ;;

  

string queryReadMessages =   " https://api.yammer.com/api/v1/messages/my_feed.json&#34 ;;

所有API调用都应该定向到api.yammer.com域。