Because the scallops search word is not convenient, so many times to add new words are in the use Youdao dictionary, and then conveniently saved to the Youdao word, but in the scallops remember the word can punch, remember the word more convenient, into the scallops page found the Scallop Word batch import incredibly once only support 10, Check the Scallops API can import new words, and then think about the use of C # batch import words? Do what you say!
Getting ready to work get scallops tokens
First you need the Scallop account (this is no nonsense), then you need to create your own application on the scallops, enter the http://www.shanbay.com/developer/wiki/intro/, click on my app to create a scallop application, specifically configured as follows
Note the callback address
Get tokens when you're finished creating apps
CLIENT_ID is your appkey, enter this address will prompt authorization (first login to their own users), and then agree to the authorization will jump to a URL, you will see Access_token, copy down standby.
Export Youdao Dictionary
Open Youdao Dictionary-word-, browse tab, manage export to file, all categories, export to XML file, alternate.
Start Programming Ideas
1) The Scallop Word insertion method has two interfaces: one is to get the ID based on the word and the other to add the word based on the ID
2) because the scallops have single account import restrictions (single user single app 200/hour), if too many imported words will be forbidden to access, so need to add a timer automatically added remaining words
The core code is as follows:
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Net;usingSystem.Text;usingSystem.Threading.Tasks;usingNewtonsoft.json;usingNewtonsoft.Json.Linq;namespaceimportnewwordstoshanbay{ Public classShanbayimporthelper { Public Static intGetshanbaywordid (stringWordstringAccess_token) { Try { varresult = Httphelper.httpget ("https://api.shanbay.com/bdc/search/","word="+ Word +"&access_token="+Access_token); Jobject JSON=jobject.parse (Result); if(JSON. Property ("Status_code"). value.tostring () = ="0") { varWordid = Jobject.parse (JSON. Property ("Data"). Value.tostring ()). Property ("ID"). Value.tostring (); return int. Parse (Wordid); } Else return-1; } Catch(Exception ex) {return 0; } } Public Static BOOLAddnewwordtoshanbay (intWordid,stringAccess_token) { Try { vardata ="{\ "id\":"+ Wordid +"}"; varPostresult = Httphelper.httppost ("https://api.shanbay.com/bdc/learning/", Access_token, data); Jobject Postjsonresult=Jobject.parse (Postresult); if(Postjsonresult.property ("msg"). Value.tostring (). ToUpper () = ="SUCCESS") { return true; } } Catch(Exception ex) {}return false; } }}
HTTP helper Classes
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Net;usingSystem.Net.Security;usingSystem.Text;usingSystem.Threading.Tasks;namespaceimportnewwordstoshanbay{ Public classHttphelper { Public Static stringHttpPost (stringUrlstringTokenstringpostdatastr) {Encoding Encoding=Encoding.UTF8; HttpWebRequest Request=(HttpWebRequest) webrequest.create (URL);request. ProtocolVersion=httpversion.version11;Request. Method ="POST"; Request. Headers.add ("Authorization",string. Format ("Bearer {0}", token)); Request. ContentType="Application/json"; Request. Referer=NULL; Request. AllowAutoRedirect=true; Request. Accept="*/*"; byte[] buffer =encoding. GetBytes (POSTDATASTR); Request. ContentLength=buffer. Length; Request. GetRequestStream (). Write (Buffer,0, buffer. Length); HttpWebResponse Response=(HttpWebResponse) request. GetResponse (); using(StreamReader reader =NewStreamReader (response. GetResponseStream (), Encoding.UTF8)) {returnReader. ReadToEnd (); } }
Public Static stringHttpGet (stringUrlstringpostdatastr) {HttpWebRequest Request= (HttpWebRequest) webrequest.create (Url + (Postdatastr = =""?"":"?") +postdatastr); Request. Method="GET"; Request. ContentType="Text/html;charset=utf-8"; HttpWebResponse Response=(HttpWebResponse) request. GetResponse (); Stream Myresponsestream=Response. GetResponseStream (); StreamReader Mystreamreader=NewStreamReader (Myresponsestream, Encoding.GetEncoding ("Utf-8")); stringRetString =Mystreamreader.readtoend (); Mystreamreader.close (); Myresponsestream.close (); returnretstring; } }}
Import Settings interface
Import Status View (timed Auto Import of remaining non-imported words)
All the words are added after all the imports have been completed to view the scallop Word book.
enjoy!
C # import Youdao dictionary word book to scallops