How can I creat a client with our API Key and Username/Password of a user #1
Comments
Hello, Currently there is no way to set the access token as string directly, because I didn't think of this scenario. A workaround could be to create a Example:
You have to repeat this on every instantiation of the client. Therefore I recommend to serialize the Important to note, is, that you need to set the Further note: An username and password are not required, if you have an access token, because the user will be identified by the access token. Maybe I will implement PIN authentication, but I'm not sure about this, because it is deprecated. If your intention is to set the access token manually, I will see how to fix this. I hope I could help you. |
You can now set the access token directly in the client. Example:
or
|
Sound good.
But how i can set the username and passwort of an user to get a new token? Atm we don't need a pin or application permission that has to be confirmed by user. Sorry, my english is not the best, I hope you understand me :-) |
Okay, I think, I misunderstood you a little. :-)
Yes, it's the Client ID, that you get, when you create your application on Trakt.tv.
Yes, if you mean by "login" the authentication for your application by the user. Either you already have an access token, then you're good to go and just use it by setting it via
Or you don't have an access token. Then you must authenticate your application to get an access token. TraktApiSharp distinguishes between requests, that require authorization with an access token, and requests, that don't require authorization. Just like the Trakt API. If you only need requests, that don't require authorization (e.g. retrieving data about movies and shows), then you only have to provide your application client id to the library.
If you also need requests, that require authorization (e.g. retrieving information about users, checkins, syncs or post requests), then you also have to provide your access token to the library.
If you don't have an access token, then you have two options: OAuth authentication and Device authentication. The application client secret, that you also get, when you create your application on Trakt.tv, is only needed for the authentication process. So, to make authentication possible, to get an access token, you have to provide your client id and client secret to the library.
With OAuth authentication you have to follow these steps to get an access token:
With Device authentication you have to follow these steps to get an access token:
The You can set or get an instance of it via
TraktApiSharp doesn't need the username or password, neither for authentication nor otherwise. Only the
If you're using this library, you don't have to deal with request headers anymore. It's already implemented in the library. ;-) I also added three properties to the client for checking validity.
A proper documentation for using this library is already on my todo list. ;-) |
im trying the same but i cant get your sample code to work since i get errors on accesstoken and usercode and verificationurl. Am i missing a using statement ? |
@ludwich What kind of errors / exceptions do you get? |
i cant get the var accessToken = traktAuthorization.AccessToken; to work since i get red lined on AccessToken and the same on device.VerificationUrl and device.UserCode. installed from github first but tested with nuget too now and it cant find the defenition |
@ludwich Which version do you use? There was a bug with device authentication in version 0.1.0, that got fixed in version 0.1.1 Did you check the returned TraktDevice, if it is null?
To get any Trakt exceptions, wrap all TraktClient calls in a try/catch-block, like this:
|
Which defnition specifically? The only dependency is Newtonsoft.Json, but that should be installed automatically, if you use NuGet. |
Sorry im really new to c# .. I have newtonsoft for json in other programs so i have that but now i get async errors from await call. I cant call it from main ? is there a better place to discuss ? |
Yeah, async / await can be tricky, if you're new to it. The library basically just returns Task objects, which are awaitable and therefore can be executed in a different thread. For example:
Nr. 2 returns the actual result (in this case, the Nr. 1 returns a
to get the actual To use
But unfortunately, this is not allowed in your case with the There are two good blogposts about async / await: |
ok. Well atleast this moves me forward =) Ill try again tonight with building functions instead in a console program as you guessed correctly. Thanks for your hardwork and nice support man. Have a great weekend. |
I'm glad, I could help. |
Hi
sorry, don't found a forum or something other to post my question.
We use our own API to get and set informations to and from Trakt.tv. But we have added only some basic requests and our plan is to switch to your wrapper.
We have a API key for our app (vb.NET), but I don't understand how I can create a client with our API key and username/password that the user fills in settings. Do you can help me with this?
The text was updated successfully, but these errors were encountered: