question

sarahjohn8714 avatar image
sarahjohn8714 asked Tyler Liu answered

Web app with RingCentral API

Hello All,


I am trying to get my C# web application to log into RingCentral using their API. I am new to using Web API, and not sure how to use RC. I have viewed their docs, but I have had no success. https://github.com/ringcentral/ringcentral-csharp-client | Crystal Reports


I know my credz work, because I can log into their portal, and all my key's have not changed.


First error I receive when adding the "await" key word is it want to change my method from Page_Load to an "async" method. Secondly is page inheritance should this be System.web.ui.page or Ringcentral.page?


In the end I want to be able to login and retrieve inbound and outbound call logs and display them in a gridview.


I am using VS 2017, and it's a Web Forms app. I did NOT choose MVC or Web API. I can't even break on a break point.


 public partial class _Default : Page
{      //https://github.com/ringcentral/ringcentral-csharp-client        private static String appKey = ConfigurationManager.AppSettings["appKey"].ToString();      private static String appSecret = ConfigurationManager.AppSettings["appSecretKey"].ToString();      private static bool isProduction = Convert.ToBoolean(ConfigurationManager.AppSettings["IsProduction"].ToString());        private static String userName = ConfigurationManager.AppSettings["username"].ToString();      private static String extension = ConfigurationManager.AppSettings["extension"].ToString();      private static String password = ConfigurationManager.AppSettings["password"].ToString();      private RestClient rc = null;        protected async void Page_LoadAsync(object sender, EventArgs e)      {            rc = new RestClient(appKey, appSecret, isProduction);          await rc.Authorize(userName, extension, password);        }  }

An example web app or stubbed out code for a web app would be very helpful. Thanks, KSS

getting started
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

ralph-r1798 avatar image
ralph-r1798 answered Tyler Liu commented
We are still using the older SDK package that isn't async and I am not sure how to you can go about making the Page_Load event async but you could:
  1. Remove the async keyword from Page_LoadAsync,
  2. Rename the event handler back to Page_Load
  3. Instead of using await when calling rc.Authorize() you can change that to be rc.Authorize().Result; The Result essentially turns an asynchronous call into a synchronous call.

Also, it looks like the Authorize call is returning a token, since I am not using the newer RC client I am not sure how that token is used but you may need to keep track of that returned token.
1 comment
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

RC client keeps the token itself. So after authorization you just go ahead to invoke APIs.
0 Likes 0 ·
Tyler Liu avatar image
Tyler Liu answered
https://github.com/ringcentral/ringcentral-csharp-client  is a general purpose C# library so it makes no assumption about your app. It could be either a web app or a desktop app.  You just do the authorization first followed by invoking any API endpoints.

Could you please elaborate where are you stuck? Are there any error messages?

Here is how you can do authorization:  https://github.com/ringcentral/ringcentral-csharp-client#authorization
Here is how you can list call logs:  https://github.com/ringcentral/ringcentral-csharp-client#list-all-of-the-inbound-call-logs

1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image
Tyler Liu answered
If you are uncomfortable with C# async code, please check this:  https://stackoverflow.com/questions/22628087/calling-async-method-synchronously

But if you mix sync and async code, you code will likely to hang:  https://stackoverflow.com/questions/14526377/why-does-this-async-action-hang

Overall these are C# knowledge. I can only help you so much. If you have any questions regarding RingCentral feel free to post them.
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys