2015-02-24 143 views
0

我正在尝试使用Yammer REST API来获取消息。获取OAuth令牌的过程的第一部分是成功的。我正在做错误的方式oAuth令牌传递时检索消息,因为我得到了401未授权。Yammer REST API与授权承载AccessToken返回401未授权

//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未经授权错误

回答