Pubblicare sui social network con
Pubblicare su social network con Java
Java : DOCUMENTAZIONE API
- Creare gruppo con Java
- Prendere la lista di campo di gruppo con Java
- Aggiungere un campo ad un gruppo con Java
- Cancellare un campo da un gruppo con Java
- Eliminare un contatto da un gruppo
- Assegnare un paese ad un gruppo con Java
- Prendere la lista di contatti di un gruppo con Java
- Aggiungere contatti ad un gruppo con Java
- Modificare contatti di un gruppo con Java
- Cancellare contatti di un gruppo con Java
Pubblicare sui social network con
String afilnet_class="social";
String afilnet_method="send";
String afilnet_user="user";
String afilnet_password="password";
String afilnet_to="123456";
String afilnet_message="message+test";
String afilnet_scheduledatetime="";
String afilnet_url="";
String afilnet_picture="";
// Create an URL request
String sUrl = "https://www.afilnet.com/api/http/?class="+afilnet_class+"&method="+afilnet_method+"&user="+afilnet_user+"&password="+afilnet_password+"&to="+afilnet_to+"&message="+afilnet_message+"&scheduledatetime="+afilnet_scheduledatetime+"&url="+afilnet_url+"&picture="+afilnet_picture;
URL url = new URL(sUrl);
StringBuilder builder = new StringBuilder();
BufferedReader theJSONline = new BufferedReader(new InputStreamReader(url.openStream()));
builder.append(theJSONline.readLine());
String content = builder.toString();
String afilnet_class="social";
String afilnet_method="send";
String afilnet_user="user";
String afilnet_password="password";
String afilnet_to="123456";
String afilnet_message="message+test";
String afilnet_scheduledatetime="";
String afilnet_url="";
String afilnet_picture="";
// Create the POST request
String post = "class="+afilnet_class+"&method="+afilnet_method+"&user="+afilnet_user+"&password="+afilnet_password+"&to="+afilnet_to+"&message="+afilnet_message+"&scheduledatetime="+afilnet_scheduledatetime+"&url="+afilnet_url+"&picture="+afilnet_picture;
// We generate the URL
URL myurl = new URL("https://www.afilnet.com/api/http/");
// We create the connection
HttpURLConnection con = (HttpURLConnection) myurl.openConnection();
con.setDoOutput(true);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Content-Length", String.valueOf(post.length()));
con.setRequestMethod("POST");
// We build the
OutputStream os = con.getOutputStream();
os.write(post.getBytes());
os.close();
StringBuilder sb = new StringBuilder();
int HttpResult = con.getResponseCode();
if(HttpResult == HttpURLConnection.HTTP_OK)
{
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(),"utf-8"));
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
br.close();
System.out.println(""+sb.toString());
} else {
System.out.println(con.getResponseCode());
System.out.println(con.getResponseMessage());
}
String afilnet_class="social";
String afilnet_method="send";
String afilnet_user="user";
String afilnet_password="password";
String afilnet_to="123456";
String afilnet_message="message+test";
String afilnet_scheduledatetime="";
String afilnet_url="";
String afilnet_picture="";
// Create the POST request
String post = "class="+afilnet_class+"&method="+afilnet_method+"&to="+afilnet_to+"&message="+afilnet_message+"&scheduledatetime="+afilnet_scheduledatetime+"&url="+afilnet_url+"&picture="+afilnet_picture;
// We generate the URL
URL myurl = new URL("https://www.afilnet.com/api/basic/");
// We create the connection
HttpURLConnection con = (HttpURLConnection) myurl.openConnection();
String encoded = Base64.getEncoder().encodeToString((afilnet_user+":"+afilnet_password).getBytes(StandardCharsets.UTF_8));
con.setRequestProperty("Authorization", "Basic "+encoded);
con.setDoOutput(true);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Content-Length", String.valueOf(post.length()));
con.setRequestMethod("POST");
// We build the
OutputStream os = con.getOutputStream();
os.write(post.getBytes());
os.close();
StringBuilder sb = new StringBuilder();
int HttpResult = con.getResponseCode();
if(HttpResult == HttpURLConnection.HTTP_OK)
{
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(),"utf-8"));
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
br.close();
System.out.println(""+sb.toString());
} else {
System.out.println(con.getResponseCode());
System.out.println(con.getResponseMessage());
}
Al realizzare richieste ricevera i seguenti campi:
I possibili codici di errore sono i seguenti:
Impostazioni.
Richiesta: