Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. import okhttp3.*;
  2.  
  3. import java.io.IOException;
  4. import java.io.OutputStream;
  5. import java.net.HttpURLConnection;
  6. import java.net.MalformedURLException;
  7. import java.net.URL;
  8.  
  9. /**
  10. * Created by Mattin on 2017-01-16.
  11. */
  12. public class GumblerMonitor {
  13. private final String USER_AGENT = "Mozilla/5.0";
  14. private final String URL_FIREBASE = "https://fcm.googleapis.com/fcm/send";
  15. private final String API_KEY = "AAAAEn-a4_o:APA91bHjwkui1kWxOeWqoPVIrlbKAW6tlEhWV8KeQRosxAkWyQFuJV0g2_" +
  16. "AFj80u_Hsmw5Il38iXd8WGef-sSKprsKnpq2Mcr3ZhWcTRFBkppGNtS3-LdfpikHxy3GukxJlgw2KkQA0T";
  17.  
  18. private void getPost(String topic, String message) throws IOException {
  19.  
  20. OkHttpClient client = new OkHttpClient();
  21. MediaType mediaType = MediaType.parse("application/json");
  22. RequestBody body = RequestBody.create(mediaType, "{\"to\": \"/topics/news\", " +
  23. "\"data\": { " +
  24. "\"message\": \"work?\"" +
  25. "}" +
  26. "}");
  27. Request request = new Request.Builder()
  28. .url("https://fcm.googleapis.com/fcm/send")
  29. .post(body)
  30. .addHeader("content-type", "application/json")
  31. .addHeader("authorization", "key="+API_KEY)
  32. .build();
  33.  
  34. Response response = client.newCall(request).execute();
  35. System.out.println(response.body().string());
  36.  
  37.  
  38.  
  39.  
  40. // URL url = new URL(URL_FIREBASE);
  41. // HttpURLConnection httpUrl = (HttpURLConnection) url.openConnection();
  42. // httpUrl.setDoOutput(true);
  43. // httpUrl.setRequestMethod("POST");
  44. // httpUrl.setRequestProperty("Authorization", "key="+API_KEY);
  45. // httpUrl.setRequestProperty("Content-Type", "application/json");
  46. // httpUrl.setRequestProperty("news", "woop");
  47. // OutputStream outputStream = httpUrl.getOutputStream();
  48. // outputStream.write(URL_FIREBASE.getBytes());
  49.  
  50. }
  51. public static void main(String[] args) throws Exception{
  52. GumblerMonitor gumblerMonitor = new GumblerMonitor();
  53. gumblerMonitor.getPost("news", "message");
  54.  
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement