This article has shared with you the method of obtaining AccessToken for your reference. The specific content is as follows
AccessToken method
public static Access_token GetAccessToken() { string formatString = ("/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", AppId, AppSecret); Access_token res = new Access_token(); HttpWebRequest request = (HttpWebRequest)(formatString); = "GET"; = "text/html;charset=UTF-8"; HttpWebResponse response = (HttpWebResponse)(); Stream myResponseStream = (); StreamReader myStreamReader = new StreamReader(myResponseStream, ("utf-8")); string retString = (); (); (); if (("7200") > 0) { Access_token token = new Access_token(); token = <Access_token>(retString); res.access_token = token.access_token; res.expires_in = token.expires_in; } return res; }
Access_token class structure
public class Access_token { public Access_token() { // //TODO: Used to verify whether Access_token expires entity // } string _access_token; string _expires_in; /// <summary> /// The obtained voucher /// </summary> public string access_token { get { return _access_token; } set { _access_token = value; } } /// <summary> /// The validity time of the voucher, unit: seconds /// </summary> public string expires_in { get { return _expires_in; } set { _expires_in = value; } } }
method
/// <summary> /// Convert JSON object to Model/// </summary> /// <typeparam name="T"></typeparam> /// <param name="szJson"></param> /// <returns></returns> public static T ParseFromJson<T>(string szJson) { T obj = <T>(); using (MemoryStream ms = new MemoryStream(Encoding.(szJson))) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(()); return (T)(ms); } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.