Getting the Access Token - OpenApiDeveloperLibrary.dll ?

Created at 26 Jul 2017, 13:44
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CT

ctid320188

Joined 19.04.2017

Getting the Access Token - OpenApiDeveloperLibrary.dll ?
26 Jul 2017, 13:44


Hi,

Just looking at getting access to users Account Details. I have seen that I need to create an Application on my spotware account etc and all that is fine but the Return URL comes back to some C# code example so I can obtain the Access Token:

            if (HttpContext.Current.Request.QueryString["code"] != null)
                {
                    var code = HttpContext.Current.Request.QueryString["code"];
                    var redirectUri = Session["Url"].ToString();
                    var token = AccessToken.GetAccessToken(_connectUrl, code, redirectUri, _clientId, _clientSecret);
                    var tokenString = token.Token; 
                    if (tokenString != null)
                    {
                        tcMainContainer.Enabled = true;
                        var profile = Profile.GetProfile(_apiUrl, tokenString);
                        var accounts = TradingAccount.GetTradingAccounts(_apiUrl, tokenString);
                        ddlTradingAccounts.DataSource = accounts;
                        ddlTradingAccounts.DataBind();
                        Session["Token"] = tokenString;
                        Session["RefreshToken"] = token.RefreshToken;
                    }
                }

But I need to use:

     using Connect_API.Accounts;
     using Connect_API.Trading;

But I am unable to locate the OpenApiDeveloperLibrary.dll file anywhere.

Is this still available or is there now a different way to obtain the access token?

Any help would be good.

Thank you


@ctid320188
Replies

Spotware
26 Jul 2017, 14:09 ( Updated at: 21 Dec 2023, 09:20 )

Dear Trader,

Thanks for posting your question in the forum. It seems that you are using the Connect API Web Example. The code for the missing libraries is located in a separate project within the same solution.

Have you downloaded both projects from GitHub? If you open the solution, it will contain both projects and you will be able to build without problems.

Best Regards,

cTrader Team

 


@Spotware

ctid320188
26 Jul 2017, 14:16

Hi,

Yes I did download both projects within the solution but it will not build, it comes up with many issues and there is no dll located in the project:

one error of which is:

OpenApiDeveloperLibrary\bin\Debug\OpenApiDeveloperLibrary.dll' could not be found

Thank you


@ctid320188

Spotware
26 Jul 2017, 14:24 ( Updated at: 21 Dec 2023, 09:20 )

Hi again,

Can you please check if the Connect API Library project is referenced properly? Please expand the References section of Connect API Web and verify that the reference exists and doesn't have any issues. You should see the following

 

In case there is an issue e.g. a yellow sign, try to add the reference again manually.

Best Regards,

cTrader Team


@Spotware

ctid320188
26 Jul 2017, 14:31

For the Connect API Library I do see a correct reference without a yellow sign but when I look at the reference properties and it's path, I view the folder that it references the DLL and there is no DLL located in that folder.


@ctid320188

Spotware
26 Jul 2017, 14:39

Hi,

Can you please remove it and try to add it again manually? Please follow the steps below

  1. Go to References.
  2. Select Connect API Library and press Delete.
  3. Right click on References.
  4. Select Add Reference
  5. Select Projects
  6. Select Connect API Library
  7. Press OK
  8. Try to build again

Let us know if the above fixes the problem

Best Regards,

cTrader Team


@Spotware

ctid320188
26 Jul 2017, 14:57

Turns out it was some of the repository nugets that were not updating in the ConnectAPILibrary project even though they tried to reload/install and even after an update of all packages.

In the end I hade to uninstall RestSharp, Newtonsoft, GoogleProtocolBuffers and GoogleProtocolBuffers.Serialization references/packages.

Then re-install them.


Seems to build ok now.

Thank you for your help.


@ctid320188