by
5,032 33
1
6
2,930
0
Top 1% !
Popular
Famous
Specified
Refined
OpenSource
Popularity: 4240th place
Created
Modified Sep 18, 2013

Published on:

No tags for this snippet yet.
Architecturex86_64
InputName0snippet
InputType0Snippet
JVMjre6
LanguageJava
LicenseMIT_X11
MethodNamesaveSnippet
OSWindows
OutputTypelong

Snip2Code APIs: Programmatically Add A Snippet

This is the fastest way to add a snippet to your bucket in Snip2Code in Java. Be sure to be logged in before sending such request.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/11212/Snip2Code-APIs--Programmatically-Add-A-S?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public long saveSnippet(Snippet snippet) { //Check that the client has been already logged in, and if this is not the case, automatically login: if (!checkLogin()) { return -1; } //send the request and parse the response: String content = serialize(snippet); //you can use a third party library to pass from objecto to json-encoded request... String contentToSend = ""; try { contentToSend = "content=" + URLEncoder.encode(content, "UTF-8"); } catch (UnsupportedEncodingException e) { return -1; } String CREATE_SNIPPET_URL = "http://www.snip2code.com/Snippets/Add"; String response = sendPostReq(CREATE_SNIPPET_URL, contentToSend); S2CResObj<Object> resp = deserialize(response); //you can use a third party library to pass from json-encoded response to the object... //build the result: if ((resp != null) && (resp.getStatus() == ErrorCodes.OK)) { try { return Long.parseLong(resp.getData().toString()); } catch (Exception e) { return -1; } } return -1; }

Other Steps and Solutions

If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus