News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Not able to get token from ringcentral api error "Unauthorized for this grant type"
Tags: getting started
Nov 14, 2017 at 2:59am   •   6 replies  •  0 likes
sagar-patel

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


6 Answers
answered on Nov 16, 2017 at 12:24am  
Does Anyone have code snippet for oauth 2.0 for asp.new web-form.
then please help me by providing it.


Thank You.



 0
answered on Nov 15, 2017 at 7:55am  
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

 0
answered on Nov 15, 2017 at 3:44am  
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

 0
answered on Nov 15, 2017 at 12:16am  
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.

 0
answered on Nov 14, 2017 at 4:57pm  
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

 0
answered on Nov 14, 2017 at 3:45pm  
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


 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us