Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exchange code for token for importing gmail address book

Tags:

c#

oauth-2.0

I am getting problem as I got the code and now I want access token in exchange of code but as pure google documentation to exchange code for token u need to send parameters

  • code The authorization code returned from the initial request
  • client_id The client_id obtained during application registration
  • client_secret The client secret obtained during application registration
  • redirect_uri The URI registered with the application
  • grant_type As defined in the OAuth 2.0 specification, this field must contain a value of authorization_code and by

    var parameters = new OAuth2Parameters {
        code =
        ClientId = "",
        ClientSecret = "",
        RedirectUri = "",
        Scope = "https://www.google.com/m8/feeds",
        grant_type =,
    };
    OAuthUtil.GetAccessToken(parameters);
    

I am forming parameters but OAuth2Parameters doesn't contain definition for grant type and google send bad server request error. Can anyone please help me with the code to exchange code for access token and how to exchange that? This is the link in which it is said that in which form google url have to be made https://developers.google.com/accounts/docs/OAuth2WebServer#formingtheurl so kindly help me and if i pass to url withour grant type parameter then it sends error saying

Could not load file or assembly 'Newtonsoft.Json, Version=4.0.5.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

like image 311
nikhil shrma Avatar asked Nov 13 '22 00:11

nikhil shrma


1 Answers

If you look in the link you posted it gives you the answer:

grant_type As defined in the OAuth 2.0 specification, this field must contain a value of authorization_code.

Set the value to the literal string "authorization_code"

grant_type = "authorization_code",
like image 136
Brian from state farm Avatar answered Nov 14 '22 23:11

Brian from state farm