我想從使用他們的API和oAuth的uStream獲取數據。我可以獲得身份驗證令牌,該令牌在Rest API Client中可以工作,並且可以獲取數據。然而,我不能在我的項目中獲取數據...我不斷收到401 UNAUTH ..oAuth uStream API
代碼:
protected void Page_Load(object sender, EventArgs e)
{
var client = new RestClient("https://www.ustream.tv/oauth2/token");
var request = new RestRequest(Method.POST);
request.AddHeader("authorization", "Basic xxxxxxxxxxxxxxxxxx");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", "client_secret=xxxxxxxxxxxxx&client_id=xxxxxxxxxxxx&grant_type=client_credentials&=", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
IRestResponse<TokenObject> response2 = (IRestResponse<TokenObject>)client.Execute<TokenObject>(request);
var tknName = response2.Data.access_token;
GetData(tknName);
}
public void GetData(string token)
{
var client = new RestClient("https://api.ustream.tv/channels/206844441.json");
var request = new RestRequest(Method.GET);
request.AddHeader("authorization", "Bearer" + token);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
IRestResponse jsonResponse = client.Execute(request);
IRestResponse<Channel> json2Response2 = (IRestResponse<Channel>)client.Execute<Channel>(request);
var blah = json2Response2.Content;
}
的jsonResponse回來401 ...但我可以使用令牌API客戶端,比如失眠它會工作......我可以獲取數據。
關於我在做什麼錯的任何想法?
謝謝!
您可以添加一些代碼,使您的答案更清晰嗎? –
完成後,增加了一個例子 –