question

sagar-patel7810 avatar image
sagar-patel7810 asked sagar-patel7810 answered

Not able to get token from ringcentral api error "Unauthorized for this grant type"

using RingCentralSDK


I am not able to get token.

when ever i try to authorize it gives error "Unauthorized for this grant type"



here is my code

Unauthorized for this grant type




using RingCentral;

using RingCentral.Http;

using System.Net.Http;

using Newtonsoft.Json.Linq;

using Newtonsoft.Json;



/// <summary>

/// Summary description for Bulk_sms

/// </summary>

public class Bulk_sms

{


public string authid = "PZurrww4RtyPR1it0KyI9w", authtoken = "sJoF2hukSg637r-f3p2JwAbYUFC1ohQuO13obpG4MBYg", account = "+13133956838", password = "sagar@123";



public ApiResponse send_bulk(string src, string dest, string text)

{


try

{


src = "+" + src;

dest = "+" + dest;


var sdk2 = new SDK(authid, authtoken, SDK.Server.Sandbox, "SMS", "1");


sdk2.Platform.Login(account, "101", password, true);




//var body = text;

//var from = src;

//var to = dest;

//var jsonData = "{\"to\": [{\"phoneNumber\": \"" + to + "\"}]," +

// "\"from\": {\"phoneNumber\": \"" + from + "\"}," +

// "\"text\": \"" + text + "\" }";

//string SmsEndPoint = "/restapi/v1.0/account/~/extension/~/sms";

//Request request = new Request(SmsEndPoint, jsonData);

//ApiResponse response = sdk2.Platform.Post(request);

//return response;

var requestBody = new

{


text = text,

from = new { phoneNumber = src },

to = new object[] { new { phoneNumber = dest } }

};

var jsonString = JsonConvert.SerializeObject(requestBody);

var request = new Request("/restapi/v1.0/account/~/extension/~/sms", jsonString);

ApiResponse response = sdk2.Platform.Post(request);

return response;

}

catch (Exception)

{



throw;

}

}



Please Help Me...????????


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.

Phong Vu avatar image
Phong Vu answered
Hi Sagar,

You code is not really readable. I guess you are trying to use the RingCentral C# SDK right? Please use this SDK https://github.com/ringcentral/ringcentral-csharp-client and read the instructions and see sample code on the README page to setup and use the SDK correctly.

You need to create and initialize a client instance
using RingCentral;
rc = new RestClient("appKey", "appSecret");

Then call the authorize function to get the accessToken
await rc.Authorize("username", "extension", "password");  
Goto the Send SMS section to see how to post a SMS request.

Read this for more information about SMS
https://developer.ringcentral.com/api-docs/latest/index.html#!#RefSMSMessages.html

Hope this helps,
+ Phong

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
Hi Sagar,

Please search this community for "Unauthorized for this grant type". This question has been answered. It is not a coding issue but an account issue. Phone is correct that you should use  https://github.com/ringcentral/ringcentral-csharp-client
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.

sagar-patel7810 avatar image
sagar-patel7810 answered
my app platform-Type : Browser-Base
i am developing a web-app/ website in asp.net C#

i have tried the  ringcentral-csharp-client
i do not get the token  it just keeps on waiting to get token response.
it just do not go beyond await.
in testing api it tried to send a message using phone number  and it was delivered.

here is my code

using System;
using RingCentral;

        private static async System.Threading.Tasks.Task<string> GetAuthorized()
        {
            RestClient rc = null;

            string appKey = "PZuit0KyI9w";
            string appSecret = "sJoF2hukSg637r-f3p2JwAbYUFC1ohQuO13obpG4MBYg";
            string phoneNumber = "";
            string password = "";

            rc = new RestClient(appKey, appSecret);

            await rc.Authorize(phoneNumber, "101",password);

            var tokenString = rc.token.access_token;

            var extension = rc.Restapi().Account().Extension();

            var requestBody = new
            {
                text = "hello -- Vidhyut",
                from = new { phoneNumber = phoneNumber },
                to = new object[] { new { phoneNumber = "+15162190172" } }
            };

            var response = await extension.Sms().Post(requestBody);

            return tokenString;
        }

please help me.
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.

sagar-patel7810 avatar image
sagar-patel7810 answered
What could be the Grant Type if i am using RingCentral.Client.

I am developing this application in ASP.Net WebForm 

Please guide me

Thanks
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.

Phong Vu avatar image
Phong Vu answered
Hi Sagar,

With the Browser-Base platform type, you have to implement the 3-legged authentication. See this demo for some code and understanding the flow.  https://github.com/ringcentral/ringcentral-demos-oauth

Otherwise, you have to change the platform type to Server/Web and access RingCentral APIs from the your server code.

Unfortunately, you cannot change the platform type after your app is created. Either you create a new app and select the correct type. Or let me know your app name so I can help change it.

+ Phong
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.

sagar-patel7810 avatar image
sagar-patel7810 answered
Does Anyone have code snippet for oauth 2.0 for asp.new web-form.
then please help me by providing it.


Thank You.


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