【问题标题】:Yammer REST API with Authorization Bearer AccessToken returns 401 UnAuthorized带有授权承载访问令牌的 Yammer REST API 返回 401 UnAuthorized
【发布时间】:2015-02-24 18:24:27
【问题描述】:

我正在尝试使用 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 错误

【问题讨论】:

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


    【解决方案1】:

    改变

    字符串 queryReadMessages = "https://www.yammer.com/api/v1/messages/my_feed.json";

    字符串 queryReadMessages = "https://api.yammer.com/api/v1/messages/my_feed.json";

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

    【讨论】:

      猜你喜欢
      • 2017-06-11
      • 1970-01-01
      • 2020-07-25
      • 2020-03-24
      • 1970-01-01
      • 2021-05-26
      • 1970-01-01
      • 1970-01-01
      • 2017-07-06
      相关资源
      最近更新 更多