android - how to transfer the curl command to http post request -
i using facebook object api upload images facebook staging service. api document here http://developers.facebook.com/docs/opengraph/using-object-api/
in doucement, uses curl upload image:
curl -x post https://graph.facebook.com/me/staging_resources -f file=@images/prawn-curry-1.jpg -f access_token=$user_access_token
how can achieve same function using http post request in android app?
thanks lot!
string uri = "https://graph.facebook.com/me/staging_resources"; httpresponse response = null; try { httpclient client = new defaulthttpclient(); httppost post = new httppost(uri); multipartentity postentity = new multipartentity(); string picpath = (uri.parse(picuristr)).getpath(); file file = new file("/data/local/tmp/images.jpg"); postentity.addpart("file", new filebody(file, "image/jpeg")); postentity.addpart("access_token", new stringbody("your access token string here")); post.setentity(postentity); response = client.execute(post); } catch (clientprotocolexception e) { log.d(tag, "exception"); e.printstacktrace(); } catch (ioexception e) { log.d(tag, "exception"); e.printstacktrace(); } httpentity responseentity = response.getentity(); if (responseentity== null) { log.d(tag, "responseentity null"); return ""; }
Comments
Post a Comment