I am trying to create some kind of API I can use in a Windows 8 app, for accessing telldus live. Being completly new to OAuth and the documentation is really lacking, I just had to dive into the code.
So, I registered at telldus and got 4 keys, let's call them A, B, C and D
Public key: A
Private key: B
Token: C
Token secret: D
Then, to be able to make queries to the api, I need a header value for "Authentication" that the server will accept. Next step is to get this header value. I decided to use a wrapper for OAuth calls found at http://deanhume.com/Home/BlogPost/a-sim ... with-c-/49
It turned out it wasn't as simple as this page suggested. My code, step by step is:
1)
Code: Select all
var oauth = new OAuth.Manager();
var rtUrl = "http://api.telldus.com/oauth/requestToken";
oauth["consumer_key"] = "A";
oauth["consumer_secret"] = "B";
oauth.AcquireRequestToken(rtUrl, "POST");
2) Now I am confused. in my oauth object I now got two different values for token and token_secret than I got from telldus, which ones should I use? I tried the ones already in the object and now proceeded to next step, which is apparently to get an accesstoken:
3)
Code: Select all
OAuthResponse accessToken = oauth.AcquireAccessToken("http://api.telldus.com/oauth/accessToken", "POST", pin);
4) Anyhow, the code in 3) just throws an 401 unauthorized at me so I decided to skip this part and try to make a call to the api using this code:
Code: Select all
...
var authzHeader = oauth.GenerateAuthzHeader("http://api.telldus.com/oauth/xml", "GET");
string res = Get(new Uri("http://api.telldus.com/xml/devices/list"), authzHeader);
}
public string Get(Uri requestUri, string authHeaders)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);
request.Method = "GET";
request.ServicePoint.Expect100Continue = false;
request.ContentType = "x-www-form-urlencoded";
request.Headers["Authorization"] = authHeaders;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
return GetResponseString(response);
}
Any help is greatly appreciated, all threads in the forum regarding C# has ended unresolved and the documentation doesn't bother with C# at all.
If I can just get pass this step, and be able to send requests to the server, I can easily continue.
HELP!!!!!!
/Henrik