public boolean setdData(Context context, String filePath, String userId, String albumId, String accessToken) { boolean success = false; Bitmap bitmap = BitmapFactory.decodeFile(filePath); if (bitmap != null) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 87, baos); byte[] data = baos.toByteArray(); ByteArrayInputStream inputStream = new ByteArrayInputStream(data); HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory(); InputStreamContent content = new InputStreamContent("image/jpeg", inputStream); HttpRequest request = requestFactory.buildPostRequest(new genericUrl("https://picasaweb.google.com/data/feed/api/user/"+userId+"/"+albumId+"/default"), content); GoogleHeaders headers = new GoogleHeaders(); String fileName = "Whatever..."; headers.setSlugFromFileName(fileName); headers.setAuthorization("OAuth " + accessToken); request.setHeaders(headers); request.execute().ignore(); // Success! success = true } catch (IOException e) { } } return success; }
String placeJSON = "{"+ "\"location\": {" + "\"lat\": " + latitude + "," + "\"lng\": " + longitude + "}," + "\"accuracy\":" + accuracy + "," + "\"name\": \"" + name + "\"," + "\"types\": [\"" + type + "\"]," + "\"language\": \"en\" " + "}"; HttpRequest request; request = t.buildPostRequest(new GenericUrl(PLACES_ADD_URL), ByteArrayContent.fromString(null, placeJSON)); //Set the Google headers GoogleHeaders headers = new GoogleHeaders(); headers.setContentType("application/json"); request.setHeaders(headers); request.getUrl().put("key", "...."); request.getUrl().put("sensor", "true"); request.execute();
HttpTransport httpTransport = new NetHttpTransport(); HttpRequestFactory httpRequestFactory = httpTransport.createRequestFactory(); String data = "query=" + query; HttpContent content = new ByteArrayContent("application/x-www-form-urlencoded", data.getBytes()); GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/mqlread"); HttpRequest request = httpRequestFactory.buildPostRequest(url, content); HttpHeaders headers = new HttpHeaders(); headers.put("X-HTTP-Method-Override","GET"); request.setHeaders(headers); HttpResponse response = request.execute();
private String initiateResumableUpload() throws IOException { String URI = "https://storage.googleapis.com/" + bucket + "/" + path; GenericUrl url = new GenericUrl(URI); HttpRequest req = requestFactory.buildPostRequest(url, new ByteArrayContent("text/plain", new byte[0])); HttpHeaders headers = new HttpHeaders(); headers.set("x-goog-resumable", "start"); headers.setContentLength((long) 0); headers.setContentType("text/plain"); req.setHeaders(headers); req.setReadTimeout((int) DEFAULT_TIMEOUT); req.setResponseHeaders(headers); HttpResponse resp; try { resp = req.execute(); } catch (IOException e) { throw e; } if (resp.getStatusCode() == 201) { String location = resp.getHeaders().getLocation(); return location; } else { throw new IOException(); } }