Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import okhttp3.*;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- /**
- * Created by Mattin on 2017-01-16.
- */
- public class GumblerMonitor {
- private final String USER_AGENT = "Mozilla/5.0";
- private final String URL_FIREBASE = "https://fcm.googleapis.com/fcm/send";
- private final String API_KEY = "AAAAEn-a4_o:APA91bHjwkui1kWxOeWqoPVIrlbKAW6tlEhWV8KeQRosxAkWyQFuJV0g2_" +
- "AFj80u_Hsmw5Il38iXd8WGef-sSKprsKnpq2Mcr3ZhWcTRFBkppGNtS3-LdfpikHxy3GukxJlgw2KkQA0T";
- private void getPost(String topic, String message) throws IOException {
- OkHttpClient client = new OkHttpClient();
- MediaType mediaType = MediaType.parse("application/json");
- RequestBody body = RequestBody.create(mediaType, "{\"to\": \"/topics/news\", " +
- "\"data\": { " +
- "\"message\": \"work?\"" +
- "}" +
- "}");
- Request request = new Request.Builder()
- .url("https://fcm.googleapis.com/fcm/send")
- .post(body)
- .addHeader("content-type", "application/json")
- .addHeader("authorization", "key="+API_KEY)
- .build();
- Response response = client.newCall(request).execute();
- System.out.println(response.body().string());
- // URL url = new URL(URL_FIREBASE);
- // HttpURLConnection httpUrl = (HttpURLConnection) url.openConnection();
- // httpUrl.setDoOutput(true);
- // httpUrl.setRequestMethod("POST");
- // httpUrl.setRequestProperty("Authorization", "key="+API_KEY);
- // httpUrl.setRequestProperty("Content-Type", "application/json");
- // httpUrl.setRequestProperty("news", "woop");
- // OutputStream outputStream = httpUrl.getOutputStream();
- // outputStream.write(URL_FIREBASE.getBytes());
- }
- public static void main(String[] args) throws Exception{
- GumblerMonitor gumblerMonitor = new GumblerMonitor();
- gumblerMonitor.getPost("news", "message");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement